Found 1204 Articles for Numpy

Convert an array of datetimes into an array of strings passing hour datetime unit in Python

AmitDiwan
Updated on 28-Feb-2022 06:27:11

171 Views

To convert an array of datetimes into an array of strings, use the numpy.datetime_as_string() method in Python Numpy. The method returns an array of strings the same shape as the input array. The first parameter is the array of UTC timestamps to format. The "units" parameter sets the datetime unit to change the precision. We have passed the hours unitStepsAt first, import the required library −import numpy as npCreate an array of datetime. The 'M' type specifies datetime −arr = np.arange('2022-02-20T02:10', 6*60, 60, dtype='M8[m]')Displaying our array −print("Array...", arr)Get the datatype: −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array ... Read More

Compute the Hyperbolic sine in Python

AmitDiwan
Updated on 28-Feb-2022 06:24:37

399 Views

To compute the Hyperbolic sine, use the numpy.sinh() method in Python Numpy. The method is equivalent to 1/2 * (np.exp(x) - np.exp(-x)) or -1j * np.sin(1j*x). Returns the corresponding hyperbolic sine 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 ... Read More

Convert angles from degrees to radians with Python deg2rad()

AmitDiwan
Updated on 28-Feb-2022 06:22:30

2K+ Views

To convert a degree array to radians, use the numpy.deg2rad() method in Python Numpy. The method returns the corresponding angle in radians. This is a scalar if x is a scalar. The 1st parameter is an input angle in 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 freshly-allocated array is returned.The 3rd parameter is the condition is broadcast over the input. At locations where the condition is True, the ... Read More

Convert an array of datetimes into an array of strings passing units in Python

AmitDiwan
Updated on 28-Feb-2022 06:19:37

233 Views

To convert an array of datetimes into an array of strings, use the numpy.datetime_as_string() method in Python Numpy. The method returns an array of strings the same shape as the input array. The first parameter is the array of UTC timestamps to format. The "units" parameter sets the datetime unit to change the precision. We have passed the seconds unit.StepsAt first, import the required library −import numpy as npCreate an array of datetime. The 'M' type specifies datetime −arr = np.arange('2022-02-20T02:10', 6*60, 60, dtype='M8[m]')Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array ... Read More

Find the minimal data type of a scalar value in Python

AmitDiwan
Updated on 28-Feb-2022 06:14:59

208 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 −print("Using the min_scalar() method in Numpy") print("Result...", np.min_scalar_type(55)) print("Result...", np.min_scalar_type(38.9)) print("Result...", np.min_scalar_type(-78)) print("Result...", np.min_scalar_type(479)) print("Result...", np.min_scalar_type(2e100)) print("Result...", np.min_scalar_type(-45.8)) print("Result...", ... Read More

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

AmitDiwan
Updated on 28-Feb-2022 06:00:39

209 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

Compute the Hyperbolic cosine of the array elements in Python

AmitDiwan
Updated on 28-Feb-2022 05:56:54

104 Views

To compute the Hyperbolic cosine of the array elements, use the numpy.cosine() method in Python Numpy. The method is equivalent to 1/2 * (np.exp(x) + np.exp(-x)) and np.cos(1j*x). Returns the corresponding hyperbolic cosine 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 ... Read More

Get the Machine limits information for float with instances in Python

AmitDiwan
Updated on 28-Feb-2022 05:39:40

105 Views

To get the machine limits information for float types, use 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 npThe min is the minimum value of given dtype and max is the minimum value of given dtype.Checking for float16 type with instances −a = np.finfo(np.float16(12.5)) print("Minimum of float16 type...", a.min) print("Maximum of float16 type...", a.max)Checking for float32 type with instances −b = np.finfo(np.float32(30.5)) print("Minimum of float32 type...", b.min) print("Maximum of float32 type...", b.max)Checking for float type with instances ... Read More

Return an array with the number of nonoverlapping occurrences of substring in Python

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

134 Views

To return an array with the number of non-overlapping occurrences of substring, use the numpy.char.count() method in Python Numpy. The first parameter is the sub i.e. the substring to search for. The numpy.char module provides a set of vectorized string operations for arrays of type numpy.str_StepsAt first, import the required library −import numpy as npCreate a One-Dimensional array of strings −arr = np.array(['kATIE', 'JOHN', 'KAte', 'AmY', 'BRADley'])Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array Dimensions...", arr.ndim)Get the shape of the Array −print("Our Array Shape...", arr.shape)Get the number of elements of the ... Read More

Round to nearest integer towards zero in Python

AmitDiwan
Updated on 28-Feb-2022 05:33:38

1K+ Views

To round to nearest integer towards zero, use the numpy.fix() method in Python Numpy. It rounds an array of floats element-wise to nearest integer towards zero. The rounded values are returned as floats. The 1st parameter, x is an array of floats to be rounded. The 2nd parameter, out is a location into which the result is stored. If provided, it must have a shape that the input broadcasts to. If not provided or None, a freshly-allocated array is returned.The method returns a float array with the same dimensions as the input. If second argument is not supplied then a ... Read More

Advertisements