Programming Articles

Page 206 of 2547

Matrix Vector multiplication with Einstein summation convention in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 771 Views

Matrix Vector multiplication with Einstein summation convention uses the numpy.einsum() method in Python. This method evaluates the Einstein summation convention on operands, allowing many common multi-dimensional linear algebraic operations to be represented in a simple fashion. Syntax numpy.einsum(subscripts, operands) Parameters: subscripts − String specifying the subscripts for summation as comma separated list of subscript labels operands − Arrays for the operation Understanding Einstein Summation For matrix-vector multiplication, the notation 'ij, j' means: i represents rows of the matrix j represents columns of the matrix and elements of the ...

Read More

Vector inner product with Einstein summation convention in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 398 Views

To compute the inner product of vectors with Einstein summation convention, use the numpy.einsum() method in Python. The first parameter is the subscript string that specifies the summation pattern, and the second parameter contains the arrays for the operation. The einsum() method evaluates the Einstein summation convention on the operands. Using the Einstein summation convention, many common multi-dimensional, linear algebraic array operations can be represented in a simple fashion. In implicit mode einsum computes these values automatically. In explicit mode, einsum provides further flexibility to compute other array operations that might not be considered classical Einstein summation operations, ...

Read More

Return the cumulative product treating NaNs as one but change the type of result in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 212 Views

To return the cumulative product of array elements over a given axis treating NaNs as one, use the nancumprod() method. The cumulative product does not change when NaNs are encountered and leading NaNs are replaced by ones. Ones are returned for slices that are all-NaN or empty. The method returns a new array holding the result unless out is specified. Cumulative works like: 5, 5*10, 5*10*15, 5*10*15*20. The dtype parameter allows you to change the type of the returned array from the original array's data type. Syntax numpy.nancumprod(a, axis=None, dtype=None, out=None) Parameters a: ...

Read More

Compute the tensor dot product in Python

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

The tensor dot product is a generalization of matrix multiplication that allows you to sum products of tensor elements over specified axes. NumPy's tensordot() function computes this operation by taking two tensors and summing their products over the axes you specify. Syntax numpy.tensordot(a, b, axes=2) Parameters a, b: Input tensors to compute the dot product axes: Can be an integer N (sum over last N axes of a and first N axes of b) or a tuple of two arrays specifying which axes to sum over Basic Example Let's start with a ...

Read More

Get the Outer product of an array and a scalar in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 284 Views

To get the outer product of an array and a scalar, use the numpy.outer() method in Python. The outer product creates a matrix where each element of the first input is multiplied by each element of the second input. Given two vectors, a = [a0, a1, ..., aM] and b = [b0, b1, ..., bN], the outer product is ? [[a0*b0 a0*b1 ... a0*bN ] [a1*b0 a1*b1 ... a1*bN ] [ ... ... ... ... ] [aM*b0 aM*b1 ... aM*bN ]] Syntax numpy.outer(a, b, out=None) ...

Read More

Get the Outer Product of an array with vector of letters in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 186 Views

The outer product of two vectors creates a matrix where each element is the product of corresponding elements from the input vectors. When working with letters and numbers, NumPy treats the operation as string repetition. Given two vectors, a = [a0, a1, ..., aM] and b = [b0, b1, ..., bN], the outer product is − [[a0*b0 a0*b1 ... a0*bN ] [a1*b0 . [ ... . [aM*b0 aM*bN ]] Syntax To get the outer product of an array with vector of letters, use the numpy.outer() method − ...

Read More

Make a grid for computing a Mandelbrot set with outer product in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 248 Views

The Mandelbrot set is a famous fractal that requires computing complex numbers on a 2D grid. To create this grid efficiently, we can use NumPy's outer product to combine real and imaginary components. Understanding the Outer Product Given two vectors, a = [a0, a1, ..., aM] and b = [b0, b1, ..., bN], the outer product is − [[a0*b0 a0*b1 ... a0*bN ] [a1*b0 . . ] [ ... . ...

Read More

Compute the sign and natural logarithm of the determinant of an array in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 289 Views

To compute the sign and natural logarithm of the determinant of an array, use the numpy.linalg.slogdet() method in Python. This function is particularly useful when dealing with large matrices where the determinant might overflow or underflow. The method returns two values: sign (representing the sign of the determinant) and logdet (the natural logarithm of the absolute value). For real matrices, sign is 1, 0, or -1. The original determinant equals sign * np.exp(logdet). Syntax numpy.linalg.slogdet(a) Parameters: a - Input array, must be a square 2-D array Returns: sign - Sign ...

Read More

Return the cumulative product of array elements over a given axis treating NaNs as one in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 225 Views

To return the cumulative product of array elements over a given axis treating NaNs as one, use the nancumprod() method. The cumulative product does not change when NaNs are encountered and leading NaNs are replaced by ones. Ones are returned for slices that are all-NaN or empty. Cumulative product works like: 5, 5×10, 5×10×15, 5×10×15×20. When NaN values are present, they are treated as 1, so the cumulative product continues without interruption. Syntax numpy.nancumprod(a, axis=None, dtype=None, out=None) Parameters The nancumprod() method accepts the following parameters ? a ? Input array axis ...

Read More

Integrate a Laguerre series in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 202 Views

To integrate a Laguerre series, use the laguerre.lagint() method in Python. The method returns the Laguerre series coefficients c integrated m times from lbnd along axis. At each iteration the resulting series is multiplied by scl and an integration constant, k, is added. The scaling factor is for use in a linear change of variable. Syntax laguerre.lagint(c, m=1, k=[], lbnd=0, scl=1, axis=0) Parameters The function accepts the following parameters ? c − Array of Laguerre series coefficients. If c is multidimensional the different axis correspond to different variables with the degree in ...

Read More
Showing 2051–2060 of 25,469 articles
« Prev 1 204 205 206 207 208 2547 Next »
Advertisements