Articles on Trending Technologies

Technical articles with clear explanations and examples

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 218 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 468 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 238 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

Determine whether the given object represents a scalar data-type in Python

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

To determine whether a given object represents a scalar data-type, use the numpy.issctype() method. This method returns a Boolean result indicating whether the input represents a scalar dtype. If the input is an instance of a scalar dtype, True is returned; otherwise, False is returned. Syntax numpy.issctype(rep) Parameters rep: The object to check. This can be a dtype, type, or any other object. Example First, import the required library − import numpy as np # Check various numpy data types print("Checking NumPy data types:") print("np.int32:", np.issctype(np.int32)) print("np.int64:", np.issctype(np.int64)) print("np.float32:", ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 241 Views

The numpy.result_type() method returns the data type that results from applying NumPy's type promotion rules to the given arguments. This is useful for determining the output type of operations between different NumPy data types without actually performing the operation. Syntax numpy.result_type(*arrays_and_dtypes) Parameters The function accepts multiple arguments representing operands whose result type is needed. These can be: arrays_and_dtypes − Arrays, scalars, or data type strings/objects How Type Promotion Works NumPy follows specific rules for type promotion: When combining arrays and scalars, the array's type takes precedence The ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 338 Views

The numpy.min_scalar_type() method finds the minimal data type that can hold a given value. For scalars, it returns the data type with the smallest size that can store the value. For arrays, it returns the array's dtype unmodified. Floating point values are not demoted to integers, and complex values are not demoted to floats. Syntax numpy.min_scalar_type(a) Parameters a − The value whose minimal data type is to be found. Can be a scalar or array-like. Basic Examples Let's start with simple scalar values to understand how the function determines minimal data types ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 796 Views

To get the approximate number of decimal digits to which a specific float type is precise, use the precision attribute of the numpy.finfo() method in Python NumPy. The finfo() function provides machine limits for floating point types. Basic Usage Import NumPy and use finfo() with a float type ? import numpy as np # Get float info for different types info16 = np.finfo(np.float16) info32 = np.finfo(np.float32) info64 = np.finfo(np.float64) print("Float16 precision:", info16.precision) print("Float32 precision:", info32.precision) print("Float64 precision:", info64.precision) Float16 precision: 3 Float32 precision: 6 Float64 precision: 15 Detailed ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 732 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 data type to get information about. What is numpy.finfo()? The numpy.finfo() function provides machine limits for floating-point types. The iexp attribute specifically returns the number of bits used for the exponent in the IEEE 754 floating-point representation ? Syntax numpy.finfo(dtype).iexp Float16 Type Checking for float16 type. The iexp gets the number of bits in the exponent portion ? ...

Read More
Showing 2481–2490 of 61,299 articles
« Prev 1 247 248 249 250 251 6130 Next »
Advertisements