Found 33676 Articles for Programming

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

AmitDiwan
Updated on 24-Feb-2022 10:49:59

147 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.The 1st parameter is the input array. The 2nd parameter is ... Read More

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

AmitDiwan
Updated on 24-Feb-2022 10:47:57

230 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. Cumulative works like, 5, 5+10, 5+10+15, 5+10+15+20.The 1st parameter is the input array. The 2nd parameter is the axis along which the cumulative sum is computed. The default (None) is to compute the cumsum over the flattened array. The 3rd parameter is the type of the returned array and of the accumulator in ... Read More

Return the type that results from applying the NumPy type promotion rules to the arguments in Python

AmitDiwan
Updated on 24-Feb-2022 10:45:43

151 Views

The numpy.result_type() method returns the type that results from applying the NumPy type promotion rules to the arguments. The 1st parameter is the operands of some operation whose result type is needed. Type promotion in NumPy works similarly to the rules in languages like C++, with some slight differences. When both scalars and arrays are used, the array’s type takes precedence and the actual value of the scalar is taken into account.StepsAt first, import the required library −import numpy as npThe numpy.result_type() method returns the type that results from applying the NumPy type promotion rules to the arguments −print("Using the ... Read More

Find the minimal data type of an array-like in Python

AmitDiwan
Updated on 24-Feb-2022 10:44:01

193 Views

The numpy.min_scalar() method finds the minimal data type. The 1st parameter is the value whose minimal data type is to be found. For scalar, returns the data type with the smallest size and smallest scalar kind which can hold its value. For non-scalar array, returns the vector’s dtype unmodified. Floating point values are not demoted to integers, and complex values are not demoted to floats.StepsAt first, import the required library −import numpy as npThe numpy.min_scalar() method finds the minimal data type. The 1st parameter is the value whose minimal data type is to be found −print("Using the min_scalar() method in ... Read More

Get the approximate number of decimal digits to which this kind of float is precise in Python

AmitDiwan
Updated on 24-Feb-2022 10:41:07

665 Views

To get the approximate number of decimal digits to which this kind of float is precise, use the precision attribute of the numpy.finfo() method in Python Numpy. The first parameter of the finfo() is the float i.e. the kind of float data type to get information about.StepsAt first, import the required library −import numpy as npChecking for float16 type. The precision is to get the approximate number of decimal digits. The iexp is to get the number of bits in the exponent portion. The min is the minimum value of given dtype. The max is the minimum value of given ... Read More

Get the number of bits in the exponent portion of the floating point representation in Python

AmitDiwan
Updated on 24-Feb-2022 10:39:21

610 Views

To get the number of bits in the exponent portion of the floating point representation, use the iexp attribute of the numpy.finfo() method in Python Numpy. The first parameter is the float i.e. the kind of float data type to get information about.StepsAt first, import the required library −import numpy as npChecking for float16 type. The iexp is to get the number of bits in the exponent portion. The min is the minimum value of given dtype. The max is the minimum value of given dtype. −a = np.finfo(np.float16(45.9)) print("Number of bits in the exponent portion float16 type...", a.iexp) print("Minimum ... Read More

Compute the Hyperbolic tangent of the array elements in Python

AmitDiwan
Updated on 24-Feb-2022 10:36:47

204 Views

To compute the Hyperbolic tangent of the array elements, use the numpy.tanh() method in Python Numpy. The method is equivalent to np.sinh(x)/np.cosh(x) or -1j * np.tan(1j*x). Returns the corresponding hyperbolic tangent values. This is a scalar if x is a scalar. The 1st parameter, x is input array. 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.The 3rd parameter is the condition is broadcast over the input. ... Read More

Compute the Hyperbolic tangent in Python

AmitDiwan
Updated on 24-Feb-2022 10:34:42

492 Views

To compute the Hyperbolic tangent, use the numpy.tanh() method in Python Numpy. Equivalent to np.sinh(x)/np.cosh(x) or -1j * np.tan(1j*x). Returns the corresponding hyperbolic tangent values. This is a scalar if x is a scalar. The 1st parameter, x is input array. 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.The 3rd parameter is the condition is broadcast over the input. At locations where the condition is True, ... Read More

Get the Machine limits information for float types in Python

AmitDiwan
Updated on 24-Feb-2022 10:32:24

674 Views

To get the machine limits information for float types, use the numpy.finfo() method in Python Numpy. The first parameter is the floating type i.e. the kind of float data type to get information about.StepsAt first, import the required library −import numpy as npThe min is the minimum value of given dtype and max is the minimum value of given dtype.Checking for float16 type −a = np.finfo(np.float16) print("Minimum of float16 type...", a.min) print("Maximum of float16 type...", a.max)Checking for float32 type −b = np.finfo(np.float32) print("Minimum of float32 type...", b.min) print("Maximum of float32 type...", b.max)Checking for float64 type −c = np.finfo(np.float64) print("Minimum of ... Read More

Get the Machine limits information for int with instances in Python

AmitDiwan
Updated on 24-Feb-2022 10:30:52

187 Views

To get the machine limits information for integer types, use the numpy.iinfo() method in Python Numpy. The first parameter is the int_type i.e. the kind of integer data type to get information about.StepsAt first, import the required library −import numpy as npThe min is the minimum value of given dtype and max is the minimum value of given dtype.Checking for int16 type with instances −a = np.iinfo(np.int16(20)) print("Minimum of int16 type...", a.min) print("Maximum of int16 type...", a.max)Checking for int32 type with instances −b = np.iinfo(np.int32(30)) print("Minimum of int32 type...", b.min) print("Maximum of int32 type...", b.max)Checking for int64 type with instances ... Read More

Advertisements