Previous topic

Mathutils

Next topic

Nonlinear operations

This Page

Linear algebra operations

The mathutils.linalg module contains several useful linear algebra operations, on NumPy arrays. All functions avoid memory allocation, by requiring the NumPy array in which to write the answer. If not specified otherwise, all arrays should be double arrays. This module requires the BLAS and LAPACK libraries.

This module defines the following functions:

  • product_matrix_vector: Computes a matrix/vector product.
  • product_matrix_matrix: Computes a matrix/matrix product.
  • outer: Computes the outer product of two vectors.
  • sum_rows: Sums out the rows of a matrix.
  • sum_columns: Sums out the columns of a matrix.
  • getdiag: Extracts the diagonal of a matrix.
  • setdiag: Sets the diagonal of a matrix.
  • multiple_row_accumulate: Accumulates the rows from a matrix into the rows of another matrix.
  • solve: Linear system solver.
  • lu: Compute the LU decomposition of a matrix.
mathutils.linalg.product_matrix_vector(A, b, x)[source]

Computes the matrix/vector product A*b=x

mathutils.linalg.product_matrix_matrix(A, B, X)[source]

Computes the matrix/matrix product A*B = X

mathutils.linalg.outer(a, b, X)[source]

Computes outer product a*b^T=X

mathutils.linalg.sum_rows(A, x)[source]

Sums out the rows of A, and puts the result in x

mathutils.linalg.sum_columns(A, x)[source]

Sums out the columns of A, and puts the result in x

mathutils.linalg.getdiag(A, x)[source]

Copies the diagonal of A in x

mathutils.linalg.setdiag(A, x)[source]

Sets the diagonal of A to x

mathutils.linalg.multiple_row_accumulate(X, rows, Y)[source]
Computes the following:
for i,r in enumerate(rows):
Y[r,:] += X[i,:]
mathutils.linalg.solve(A, B, X, Af=None, Bf=None, pivots=None)[source]

Solves the linear system A*X = B. If provided, will use temporary variables Af, Bf (Fortran ordered double matrix arrays) and pivots (Fortran ordered integer vector array) and avoid memory allocations.

mathutils.linalg.lu(A, p, L, U, Af=None, pivots=None)[source]

Compute the LU decomposition of A[p,:] = L*U, where p is a vector of integers and permutes the rows of A. If provided, will use temporary variables Af (Fortran ordered double matrix arrays) and pivots (Fortran ordered integer vector array) and avoid memory allocations.