Found 10476 Articles for Python

Return the imaginary part of the complex argument in Python

AmitDiwan
Updated on 25-Feb-2022 06:02:43

225 Views

To return the imaginary part of the complex argument, use the numpy.imag() method. The method returns the imaginary component of the complex argument. If val is real, the type of val is used for the output. If val has complex elements, the returned type is float. The 1st parameter, val is the input arrayStepsAt first, import the required libraries -import numpy as npCreate an array using the array() method −arr = np.array([36.+5.j , 27.+3.j , 68.+2.j , 23.+7.j])Display the array −print("Our Array...", arr)Check the Dimensions −print("Dimensions of our Array...", arr.ndim) Get the Datatype −print("Datatype of our Array object...", arr.dtype)Get the ... Read More

Return the cumulative sum of array elements over given axis treating NaNs as zero in Python

AmitDiwan
Updated on 25-Feb-2022 05:33:22

152 Views

To return the cumulative sum of array elements over a given axis treating NaNs as zero, use the nancumprod() method. The cumulative sum does not change when NaNs are encountered and leading NaNs are replaced by zeros.Zeros are returned for slices that are all-NaN or empty. The method returns a new array holding the result unless out is specified, in which it is returned. The result has the same size as a, and the same shape as a if axis is not None or a is a 1-d array. Cumulative works like, 5, 5+10, 5+10+15, 5+10+15+20. The 1st parameter is ... Read More

Get the Trigonometric inverse sin in Python

AmitDiwan
Updated on 25-Feb-2022 05:30:41

7K+ Views

The arcsin is a multivalued function: for each x there are infinitely many numbers z such that sin(z) = x. The convention is to return the angle z whose real part lies in [-pi/2, pi/2]. For real-valued input data types, arcsin always returns real output. For each value that cannot be expressed as a real number or infinity, it yields nan and sets the invalid floating point error flag. For complex-valued input, arcsin is a complex analytic function that has, by convention, the branch cuts [-inf, -1] and [1, inf] and is continuous from above on the former and from ... Read More

Get the Trigonometric tangent of an array of angles given in degrees with Python

AmitDiwan
Updated on 25-Feb-2022 05:28:55

325 Views

Trigonometric tangent is equivalent to np.sin(x)/np.cos(x) element-wise. To get the Trigonometric tangent of an array of angles given in degrees, use the numpy.tan() method in Python Numpy. The method returns the tangent of each element of the 1st parameter x. The 1st parameter, x, is an Angle, in radians (2pi means 360 degrees). Here, it is an array of angles.The 2nd and 3rd parameters are optional. The 2nd parameter is an ndarray, A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array ... Read More

Return the gradient of an N-dimensional array over given axis in Python

AmitDiwan
Updated on 25-Feb-2022 05:26:35

164 Views

The gradient is computed using second order accurate central differences in the interior points and either first or second order accurate one-sides (forward or backwards) differences at the boundaries. The returned gradient hence has the same shape as the input array. The 1st parameter, f is an Ndimensional array containing samples of a scalar function. The 2nd parameter is the varargs i.e. the spacing between f values. Default unitary spacing for all dimensions.The 3rd parameter is the edge_order{1, 2} i.e. the Gradient is calculated using N-th order accurate differences at the boundaries. Default: 1. The 4th parameter is the Gradient, ... Read More

Test whether similar float type of different sizes are subdtypes of floating class in Python

AmitDiwan
Updated on 25-Feb-2022 05:24:57

110 Views

To test whether similar float type of different sizes are subdtypes of floating class, use the numpy.issubdtype() method in Python Numpy. The parameters are the dtype or object coercible to one.StepsAt first, import the required library −import numpy as npUsing the issubdtype() method in Numpy. Checking for floating point datatype with different sizes −print("Result...", np.issubdtype(np.float16, np.floating)) print("Result...", np.issubdtype(np.float32, np.floating)) print("Result...", np.issubdtype(np.float64, np.floating))Exampleimport numpy as np # To test whether similar float type of different sizes are subdtypes of floating class, use the numpy.issubdtype() method in Python Numpy. # The parameters are the dtype or object coercible to one print("Using ... Read More

Get the Trigonometric cosine of an array of angles given in degrees with Python

AmitDiwan
Updated on 25-Feb-2022 05:23:18

5K+ Views

To find the Trigonometric cosine of an array of angles given in degrees, use the numpy.cos() method in Python Numpy. The method returns the cosine of each element of the 1st parameter x. The 1st parameter, x, is an Angle, in radians (2pi means 360 degrees). Here, it is an array of angles. The 2nd and 3rd parameters are optional.The 2nd parameter is an ndarray, A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple must have length ... Read More

Get the Trigonometric cosine of an angle in Python

AmitDiwan
Updated on 25-Feb-2022 05:21:11

2K+ Views

To find the Trigonometric cosine, use the numpy.cos() method in Python Numpy. The method returns the sine of each element of the 1st parameter x. The 1st parameter, x, is an Angle, in radians (2pi means 360 degrees). The 2nd and 3rd parameters are optional. The 2nd parameter is an ndarray, A location into which the result is stored.If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshlyallocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.The 3rd parameter is ... Read More

Integrate along the given axis using the composite trapezoidal rule in Python

AmitDiwan
Updated on 25-Feb-2022 05:19:08

167 Views

To integrate along the given axis using the composite trapezoidal rule, use the numpy.trapz() method. If x is provided, the integration happens in sequence along its elements - they are not sorted. The method returns the definite integral of ‘y’ = n-dimensional array as approximated along a single axis by the trapezoidal rule. If ‘y’ is a 1-dimensional array, then the result is a float. If ‘n’ is greater than 1, then the result is an ‘n-1’ dimensional array.The 1st parameter, y is the input array to integrate. The 2nd parameter, x is the sample points corresponding to the y ... Read More

Determine if a class is a subclass of a second class in Python

AmitDiwan
Updated on 25-Feb-2022 05:14:45

207 Views

To determine if a class is a subclass of a second class, use the numpy.issubclass_() method in Python numpy. The 1st argument is the input class. True is returned if arg1 is a subclass of arg2. The 2nd argument is the input class. If a tuple of classes, True is returned if arg1 is a subclass of any of the tuple elements. The issubclass_ is equivalent to the Python built-in issubclass, except that it returns False instead of raising a TypeError if one of the arguments is not a class.StepsAt first, import the required library −import numpy as npUsing the ... Read More

Advertisements