Return matrix rank of array using Singular Value Decomposition method in Python

AmitDiwan
Updated on 26-Mar-2026 19:22:41

771 Views

To return the matrix rank of an array using the Singular Value Decomposition (SVD) method, use the numpy.linalg.matrix_rank() method in Python. The rank of a matrix represents the number of linearly independent rows or columns, calculated as the count of singular values greater than a specified tolerance. Syntax numpy.linalg.matrix_rank(A, tol=None, hermitian=False) Parameters A: Input vector or stack of matrices whose rank needs to be computed. tol: Threshold below which SVD values are considered zero. If None, it's automatically set to S.max() * max(M, N) * eps, where S contains singular values and eps ... Read More

Compute element-wise arc tangent of x1/x2 choosing the quadrant correctly in Python

AmitDiwan
Updated on 26-Mar-2026 19:22:22

239 Views

The numpy.arctan2() function computes the element-wise arc tangent of y/x choosing the quadrant correctly. Unlike arctan(), it uses the signs of both arguments to determine which quadrant the angle is in, returning values in the range [-π, π]. Syntax numpy.arctan2(y, x) Parameters y: Array-like, the y-coordinates (first parameter) x: Array-like, the x-coordinates (second parameter) If shapes differ, they must be broadcastable to a common shape. Understanding Quadrants The function determines angles based on coordinate positions ? import numpy as np # Four points in different quadrants x = np.array([1, ... Read More

Get the Trigonometric inverse cosine in Python

AmitDiwan
Updated on 26-Mar-2026 19:22:02

6K+ Views

The inverse cosine (arccos) is a multivalued function that returns the angle whose cosine equals a given value. In NumPy, the arccos() function returns angles in the range [0, π] radians. For real-valued inputs, it always returns real output, while invalid values (outside [-1, 1]) return nan. To find the trigonometric inverse cosine, use the numpy.arccos() method. The method returns the angle of the array intersecting the unit circle at the given x-coordinate in radians [0, π]. Syntax numpy.arccos(x, out=None, where=True) Parameters The function accepts the following parameters ? x − ... Read More

Compute the determinant of an array in linear algebra in Python

AmitDiwan
Updated on 26-Mar-2026 19:21:42

327 Views

The determinant is a scalar value that provides important information about a square matrix in linear algebra. In Python NumPy, we use np.linalg.det() to compute the determinant of an array. Syntax numpy.linalg.det(a) Parameters: a − Input array (must be square matrix) Returns: The determinant of the input array as a scalar value. Basic Example Let's compute the determinant of a 2x2 matrix − import numpy as np # Create a 2x2 array arr = np.array([[5, 10], [12, 18]]) print("Array:") print(arr) # Compute the determinant det ... Read More

Return True if first argument is a typecode lower/equal in type hierarchy in Python

AmitDiwan
Updated on 26-Mar-2026 19:20:48

180 Views

The numpy.issubdtype() method returns True if the first argument is a data type that is lower or equal in the NumPy type hierarchy compared to the second argument. This is useful for checking type compatibility and inheritance relationships in NumPy arrays. Syntax numpy.issubdtype(arg1, arg2) Parameters The method accepts two parameters ? arg1 ? The data type or object coercible to a data type to be tested arg2 ? The data type to compare against in the hierarchy Understanding NumPy Type Hierarchy NumPy has a type hierarchy where specific types ... Read More

Return the data type with the smallest size and scalar kind to which both the given types be safely cast in Python

AmitDiwan
Updated on 26-Mar-2026 19:20:32

173 Views

The numpy.promote_types() method returns the data type with the smallest size and scalar kind to which both given types can be safely cast. This is useful when you need to determine the appropriate data type for operations involving mixed types. Syntax numpy.promote_types(type1, type2) Parameters type1: First data type (string or numpy dtype) type2: Second data type (string or numpy dtype) Return Value Returns the promoted data type that can safely hold values from both input types. The returned data type is always in native byte order. Basic Examples Let's start ... Read More

Return the imaginary part of the complex argument in Python

AmitDiwan
Updated on 26-Mar-2026 19:20:11

308 Views

To return the imaginary part of a complex number or array, use numpy.imag(). This method extracts the imaginary component from complex numbers. If the input is real, it returns the same type; if complex, it returns float values representing the imaginary parts. Syntax numpy.imag(val) Parameters: val − Input array or scalar with complex numbers Returns: Array of imaginary parts as float values Basic Example with Single Complex Number import numpy as np # Single complex number z = 5 + 3j print("Complex number:", z) print("Imaginary part:", np.imag(z)) ... Read More

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

AmitDiwan
Updated on 26-Mar-2026 19:19:51

258 Views

To return the cumulative sum of array elements over a given axis treating NaNs as zero, use the nancumsum() method. The cumulative sum does not change when NaNs are encountered and leading NaNs are replaced by zeros. The method returns a new array with cumulative sums computed along the specified axis. Zeros are returned for slices that are all-NaN or empty. Cumulative sum works progressively: 5, 5+10, 5+10+15, 5+10+15+20. Syntax numpy.nancumsum(a, axis=None, dtype=None, out=None) Parameters a − Input array axis − Axis along which the cumulative sum is computed. Default (None) computes ... Read More

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

AmitDiwan
Updated on 26-Mar-2026 19:19:29

405 Views

The trigonometric tangent function returns the ratio of sine to cosine for each angle. To calculate the tangent of angles given in degrees, we use NumPy's tan() function combined with degree-to-radian conversion. Syntax numpy.tan(x, out=None, where=True) Parameters x − Input array of angles in radians out − Optional output array where results are stored where − Optional condition to control where calculation is applied Converting Degrees to Radians Since numpy.tan() expects angles in radians, we multiply degrees by π/180 ? import numpy as np # Array of ... Read More

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

AmitDiwan
Updated on 26-Mar-2026 19:19:11

292 Views

The gradient function in NumPy computes the gradient of an N-dimensional array using numerical differentiation. It calculates derivatives along specified axes using central differences for interior points and forward/backward differences at boundaries. Syntax numpy.gradient(f, *varargs, axis=None, edge_order=1) Parameters The function accepts the following parameters: f − N-dimensional array containing samples of a scalar function varargs − Spacing between f values (default: unitary spacing for all dimensions) axis − Axis or axes along which the gradient is calculated (default: None for all axes) edge_order − Order of accuracy for boundary differences (1 or ... Read More

Advertisements