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

AmitDiwan
Updated on 26-Mar-2026 19:15:27

407 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
Updated on 26-Mar-2026 19:15:05

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
Updated on 26-Mar-2026 19:14:47

175 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
Updated on 26-Mar-2026 19:14:27

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
Updated on 26-Mar-2026 19:14:11

205 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
Updated on 26-Mar-2026 19:13:52

271 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
Updated on 26-Mar-2026 19:13:32

727 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
Updated on 26-Mar-2026 19:13:12

694 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

Get the Machine limits information for float types in Python

AmitDiwan
Updated on 26-Mar-2026 19:12:53

829 Views

To get the machine limits information for float types, use the numpy.finfo() method in Python NumPy. The first parameter is the floating type i.e. the kind of float data type to get information about. Syntax numpy.finfo(dtype) Where dtype is the floating-point data type such as float16, float32, or float64. Getting Float16 Limits Check the machine limits for 16-bit floating-point numbers ? import numpy as np # Get machine limits for float16 a = np.finfo(np.float16) print("Minimum of float16 type...") print(a.min) print("Maximum of float16 type...") print(a.max) Minimum of float16 ... Read More

Get the Machine limits information for integer types in Python

AmitDiwan
Updated on 26-Mar-2026 19:12:34

361 Views

To get machine limits information for integer types in Python, use the numpy.iinfo() method. This function returns an object containing the minimum and maximum values for a specified integer data type, helping you understand the range of values that can be stored. Syntax numpy.iinfo(int_type) Parameters: int_type − The integer data type to get information about (e.g., np.int16, np.int32, np.int64) Basic Example Let's check the limits for different integer types ? import numpy as np # Get machine limits for int16 info_16 = np.iinfo(np.int16) print("int16 minimum:", info_16.min) print("int16 maximum:", ... Read More

Advertisements