Programming Articles

Page 222 of 2547

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

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 261 Views

To determine if a class is a subclass of a second class, Python provides both the built-in issubclass() function and NumPy's issubclass_() method. NumPy's version is safer as it returns False instead of raising a TypeError when arguments are not classes. Syntax numpy.issubclass_(arg1, arg2) Parameters arg1 − The input class to test arg2 − The parent class or tuple of classes to check against Return Value Returns True if arg1 is a subclass of arg2, otherwise False. If arg2 is a tuple, returns True if arg1 is a subclass of ...

Read More

Get the Trigonometric sines of an array of angles given in degrees in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 459 Views

To get the trigonometric sines of an array of angles given in degrees, use the numpy.sin() method in Python NumPy. The method returns the sine of each element of the input array. Since numpy.sin() expects angles in radians, we must convert degrees to radians by multiplying by π/180. Syntax numpy.sin(x, out=None, where=True) Parameters The function accepts the following parameters: x − Input array of angles in radians out − Optional output array where results are stored where − Optional condition to control where calculation is performed Example Let's calculate ...

Read More

Return the scalar type of highest precision of the same kind as the input in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 202 Views

The np.maximum_sctype() function in NumPy returns the scalar type with the highest precision for a given data type kind. This is useful when you need to ensure maximum accuracy in calculations by upgrading to the most precise available type. Syntax numpy.maximum_sctype(dtype) Parameters dtype: Input data type. Can be a dtype object, Python type, or string representation convertible to a dtype. Basic Examples Let's see how maximum_sctype() works with different data types ? import numpy as np # Integer types - returns highest precision integer print("int →", np.maximum_sctype(int)) print("np.int32 →", ...

Read More

Return the string representation of a scalar dtype in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 354 Views

To return the string representation of a scalar dtype, use the sctype2char() method in NumPy. If a scalar dtype is provided, the corresponding string character is returned. If an object is passed, sctype2char() tries to infer its scalar type and then return the corresponding string character. Syntax numpy.sctype2char(sctype) Parameters: sctype − A scalar dtype or an object from which the dtype can be inferred Returns: A single character string representing the scalar type Basic Usage At first, import the required library − import numpy as np # ...

Read More

Return a description for the given data type code in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 276 Views

To return a description for the given data type code, use the typename() method in Python NumPy. This method provides human-readable descriptions for NumPy data type codes, making it easier to understand what each code represents. Syntax numpy.typename(char) Parameters char − The data type code (single character string) for which you want the description. Return Value Returns a string describing the data type corresponding to the given type code. Example First, import the required library − import numpy as np # Array of common NumPy data type ...

Read More

Return the cross product of two (arrays of) vectors in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 5K+ Views

The cross product of two vectors produces a third vector perpendicular to both input vectors. In Python, we use numpy.cross() to compute the cross product of two (arrays of) vectors. Syntax numpy.cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None) Parameters The numpy.cross() method accepts the following parameters: a - Components of the first vector(s) b - Components of the second vector(s) axisa - Axis of a that defines the vector(s). Default is the last axis axisb - Axis of b that defines the vector(s). Default is the last axis axisc - Axis of c ...

Read More

Generate a Pseudo Vandermonde matrix of the Hermite polynomial and x, y, z complex array of points in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 185 Views

To generate a pseudo Vandermonde matrix of the Hermite polynomial with x, y, z complex array coordinates, use the hermite.hermvander3d() method in NumPy. This function returns a 3D pseudo-Vandermonde matrix where each coordinate array contributes to different polynomial degrees. Syntax numpy.polynomial.hermite.hermvander3d(x, y, z, deg) Parameters x, y, z: Arrays of point coordinates with the same shape. Complex and float dtypes are automatically converted to complex128 or float64. deg: List of maximum degrees [x_deg, y_deg, z_deg] for each coordinate. Example Let's create complex coordinate arrays and generate their Hermite pseudo-Vandermonde matrix ? ...

Read More

Return the Norm of the matrix or vector in Linear Algebra in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 378 Views

To return the norm of a matrix or vector in Linear Algebra, use the numpy.linalg.norm() method. The norm is a mathematical concept that measures the "size" or "length" of a vector or matrix. Syntax numpy.linalg.norm(x, ord=None, axis=None, keepdims=False) Parameters The function accepts the following parameters − x − Input array. If axis is None, x must be 1-D or 2-D ord − Order of the norm (default: None for 2-norm) axis − Axis along which to compute the norm (default: None) keepdims − If True, keeps dimensions in the result (default: False) ...

Read More

Compute the eigenvalues of a complex Hermitian or real symmetric matrix in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 1K+ Views

To compute the eigenvalues of a complex Hermitian or real symmetric matrix, use the numpy.linalg.eigvalsh() method. This function returns eigenvalues in ascending order, each repeated according to its multiplicity. Parameters The eigvalsh() function accepts these parameters ? a: A complex Hermitian or real symmetric matrix whose eigenvalues are to be computed UPLO: Specifies whether to use the lower triangular part ('L', default) or upper triangular part ('U'). Only the real parts of the diagonal are considered to preserve the Hermitian property Example with Complex Hermitian Matrix Let's create a complex Hermitian matrix and ...

Read More

Test whether similar data types of different sizes are not subdtypes of each other in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 152 Views

The numpy.issubdtype() method in Python NumPy tests whether one data type is a subtype of another. When checking similar data types of different sizes (like float32 vs float64), they are not considered subtypes of each other despite being related. Syntax numpy.issubdtype(arg1, arg2) Parameters arg1, arg2: Data types or objects coercible to data types to compare for subtype relationship. Import Required Library First, import the NumPy library − import numpy as np Testing Float Data Types Check whether different float sizes are subtypes of ...

Read More
Showing 2211–2220 of 25,469 articles
« Prev 1 220 221 222 223 224 2547 Next »
Advertisements