Found 1204 Articles for Numpy

Generate a Vandermonde matrix of the Chebyshev polynomial with float array of points in Python

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

80 Views

To generate a Vandermonde matrix of the Chebyshev polynomial, use the chebyshev.chebvander() in Python Numpy. The method returns the Vandermonde matrix. The shape of the returned matrix is x.shape + (deg + 1, ), where The last index is the degree of the corresponding Chebyshev polynomial. The dtype will be the same as the converted x.The parameter, a is Array of points. The dtype is converted to float64 or complex128 depending on whether any of the elements are complex. If x is scalar it is converted to a 1-D array. The parameter, deg is the degree of the resulting matrix.StepsAt ... Read More

Compute the inverse Hyperbolic tangent of array elements in Python

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

126 Views

The arctanh is a multivalued function: for each x there are infinitely many numbers z such that tanh(z) = x. The convention is to return the z whose imaginary part lies in [-pi/2, pi/2]. The inverse hyperbolic tangent is also known as atanh or tanh^-1.To compute the inverse Hyperbolic tangent of array elements, use the numpy.arctanh() method in Python Numpy. The method returns the array of the same shape as x. 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 ... Read More

Calculate the n-th discrete difference in Python

AmitDiwan
Updated on 28-Feb-2022 06:53:23

92 Views

To calculate the n-th discrete difference, use the numpy.diff() method. The first difference is given by out[i] = a[i+1] - a[i] along the given axis, higher differences are calculated by using diff recursively. The diff() method returns the n-th differences. The shape of the output is the same as a except along axis where the dimension is smaller by n. The type of the output is the same as the type of the difference between any two elements of a. This is the same as the type of a in most cases. A notable exception is datetime64, which results in ... Read More

Return the cumulative sum of array elements treating NaNs as zero but change the type of result in Python

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

92 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 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 which the elements are summed. If dtype ... Read More

Return True if cast between scalar and data type can occur according to the casting rule in Python

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

82 Views

The numpy.can_cast() method returns True if scalar and data type can occur according to the casting rule. The 1st parameter is the scalar or data type or array to cast from. The 2nd parameter is the data type to cast to.StepsAt first, import the required library −import numpy as npChecking if scalar and data type can occur according to the casting rule. −print("Checking with can_cast() method in Numpy") print("Result...", np.can_cast(20, 'i1')) print("Result...", np.can_cast(280, 'i1')) print("Result...", np.can_cast(80, 'u1')) print("Result...", np.can_cast(300.7, np.float32)) print("Result...", np.can_cast(120.6, np.float64)) print("Result...", np.can_cast(7.2e100, np.float32)) print("Result...", np.can_cast(6.5e100, np.float64))Exampleimport numpy as np # The numpy.can_cast() method returns True if ... Read More

Return True if cast between data types can occur according to the casting rule in Python

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

76 Views

The numpy.can_cast() method returns True if cast between data types can occur according to the casting rule. The 1st parameter is the data type or array to cast from. The 2nd parameter is the data type to cast to.StepsAt first, import the required library −import numpy as npUsing the can_cast() to check if cast between data types can occur according to the casting rule −print("Checking with can_cast() method in Numpy") print("Result...", np.can_cast(np.int32, np.int64)) print("Result...", np.can_cast(np.float64, complex)) print("Result...", np.can_cast(complex, float)) print("Result...", np.can_cast('i8', 'f8')) print("Result...", np.can_cast('i8', 'f4')) print("Result...", np.can_cast('i4', 'S4'))Exampleimport numpy as np # The numpy.can_cast() method returns True if cast ... Read More

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

AmitDiwan
Updated on 28-Feb-2022 06:41:26

2K+ 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.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]')To convert an array of datetimes into an array of strings, use the numpy.datetime_as_string() method in Python Numpy −print("Result...", np.datetime_as_string(arr, unit ='m'))Exampleimport numpy ... Read More

Given the “legs” of a right triangle, return its hypotenuse in Python

AmitDiwan
Updated on 28-Feb-2022 06:38:48

370 Views

To get the hypotenuse, use the numpy.hypot() method in Python Numpy. The method returns the hypotenuse of the triangle(s). This is a scalar if both x1 and x2 are scalars. This method is equivalent to sqrt(x1**2 + x2**2), element-wise. If x1 or x2 is scalar_like, it is broadcast for use with each element of the other argument. The parameters are the leg of the triangle(s). If x1.shape != x2.shape, they must be broadcastable to a common shape.StepsAt first, import the required library −import numpy as npCreating an array with integer elements −arr = np.ones((3, 3), dtype=int)Displaying our array −print("Array...", arr)Get ... Read More

Get the Trigonometric inverse tangent of the array elements in Python

AmitDiwan
Updated on 28-Feb-2022 06:33:20

1K+ Views

The arctan is a multi-valued function: for each x there are infinitely many numbers z such that tan(z) = x. # The inverse tangent is also known as atan or tan^{-1}.The convention is to return the angle z whose real part lies in [-pi/2, pi/2]. For real-valued input data types, arctan 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, arctan is a complex analytic function that has [1j, infj] and [-1j, -infj] as branch cuts, and is ... Read More

Get the Trigonometric inverse tangent in Python

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

3K+ Views

The arctan is a multi-valued function: for each x there are infinitely many numbers z such that tan(z) = x. The convention is to return the angle z whose real part lies in [-pi/2, pi/2]. The inverse tangent is also known as atan or tan^{-1}.For real-valued input data types, arctan 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, arctan is a complex analytic function that has [1j, infj] and [-1j, -infj] as branch cuts, and is continuous ... Read More

Advertisements