Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 205 of 2547
Integrate a Laguerre series and set the order of integration in Python
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. Syntax numpy.polynomial.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, different axes correspond to different variables m − Order of integration, must be positive (Default: 1) k − Integration constant(s). If k == ...
Read MoreCompute the condition number of a matrix in linear algebra in Python
The condition number of a matrix measures how sensitive the solution of a linear system is to changes in the input. A low condition number indicates a well-conditioned matrix, while a high condition number suggests an ill-conditioned matrix. In Python, we use numpy.linalg.cond() to compute this value. Syntax numpy.linalg.cond(x, p=None) Parameters x: The matrix whose condition number is sought. p: Order of the norm used in computation (None, 1, -1, 2, -2, 'fro'). Basic Example Let's compute the condition number of a 3x3 matrix ? import numpy as np from ...
Read MoreReturn the negative infinity Norm of the matrix in Linear Algebra in Python
To return the negative infinity norm of a matrix in Linear Algebra, use the LA.norm() method with -np.inf as the order parameter. The negative infinity norm returns the minimum row sum of absolute values in the matrix. Syntax numpy.linalg.norm(x, ord=-np.inf, axis=None, keepdims=False) Parameters The key parameters for calculating negative infinity norm ? x − Input array (1-D or 2-D) ord − Order of norm. Use -np.inf for negative infinity norm axis − Axis along which to compute the norm (default: None) keepdims − Whether to keep dimensions in result (default: False) ...
Read MoreReturn the infinity Norm of the matrix in Linear Algebra in Python
The infinity norm of a matrix is the maximum row sum of absolute values. In NumPy, we use LA.norm() with np.inf parameter to calculate this norm in Linear Algebra operations. Syntax numpy.linalg.norm(x, ord=None, axis=None, keepdims=False) Parameters x − Input array (1-D or 2-D) ord − Order of the norm. Use np.inf for infinity norm axis − Axis along which to compute the norm keepdims − Whether to keep dimensions in the result Example Let's calculate the infinity norm of a 3×3 matrix ? import numpy as np from ...
Read MoreReturn the Norm of the vector over given axis in Linear Algebra in Python
The norm of a vector or matrix measures its magnitude or size. In NumPy, you can calculate various types of norms using numpy.linalg.norm(), including vector norms along specific axes. Syntax numpy.linalg.norm(x, ord=None, axis=None, keepdims=False) Parameters x: Input array (vector or matrix) ord: Order of the norm (default is 2-norm) axis: Axis along which to compute the norm keepdims: Whether to keep dimensions in the result Basic Vector Norm Example Let's start with calculating the norm of a simple vector ? import numpy as np from numpy import linalg as LA ...
Read MoreGet the Kronecker product of two arrays in Python
The Kronecker product is a mathematical operation that creates a composite array from two input arrays. In NumPy, you can compute the Kronecker product using the numpy.kron() method. The Kronecker product takes blocks of the second array scaled by elements of the first array. If a.shape = (r0, r1, .., rN) and b.shape = (s0, s1, ..., sN), the result has shape (r0*s0, r1*s1, ..., rN*sN). Syntax numpy.kron(a, b) Parameters: a, b: Input arrays Returns: Kronecker product of the input arrays Example with 1D Arrays Here's how to compute ...
Read MoreRaise a square matrix to the power n in Linear Algebra in Python
To raise a square matrix to the power n in Linear Algebra, use the numpy.linalg.matrix_power() function in Python. For positive integers n, the power is computed by repeated matrix squarings and matrix multiplications. If n == 0, the identity matrix of the same shape is returned. If n < 0, the inverse is computed and then raised to the abs(n). Syntax numpy.linalg.matrix_power(a, n) Parameters The function accepts the following parameters ? a − A square matrix to be raised to the power n − The exponent that can be any integer (positive, ...
Read MoreEvaluate the lowest cost contraction order for an einsum expression in Python
To find the optimal contraction order for an einsum expression, use numpy.einsum_path(). This function analyzes different ways to perform the tensor contractions and returns the most efficient path to minimize computational cost. What is einsum_path()? The einsum_path() function evaluates different contraction orders for Einstein summation operations. It returns a tuple containing the optimal contraction path and detailed information about the optimization process. Syntax numpy.einsum_path(subscripts, *operands, optimize='greedy') Parameters subscripts − String specifying the subscripts for summation using Einstein notation operands − Input arrays for the operation optimize − Optimization strategy ('greedy', 'optimal', ...
Read MoreTensor contraction with Einstein summation convention in Python
Tensor contraction with Einstein summation convention is a powerful technique for performing complex multi-dimensional array operations. Python's numpy.einsum() method provides an elegant way to implement tensor contractions using subscript notation. Understanding Einstein Summation The Einstein summation convention allows you to represent complex tensor operations using subscript labels. When indices appear in both input tensors but not in the output, they are automatically summed over (contracted). Syntax numpy.einsum(subscripts, *operands) Parameters: subscripts − String specifying the subscripts for summation as comma-separated labels operands − Input arrays for the operation Example: Tensor Contraction ...
Read MoreVector outer product with Einstein summation convention in Python
The outer product of two vectors creates a matrix where each element is the product of corresponding elements from the input vectors. NumPy's einsum() function provides an elegant way to compute outer products using Einstein summation notation. Understanding Einstein Summation The Einstein summation convention uses subscripts to specify which dimensions to multiply and sum. For outer products, we use the notation 'i, j' where i and j represent different dimensions that remain separate (no summation). Basic Outer Product Example import numpy as np # Create two vectors vector1 = np.array([1, 2]) vector2 = np.array([0, ...
Read More