Questions tagged [linear-algebra]

Linear Algebra is a core body of mathematics studying vector spaces and linear mappings between these spaces. Key topics include: matrices, vectors, simultaneous systems of linear equations, diagonal form, eigenvalues, eigenvectors, projections, points, lines, planes, hyperplanes, rotations and reflections.

Linear Algebra is a core body of mathematics studying vector spaces and linear mappings between these spaces. It has extensive applications in computer graphics, economics, engineering, and control systems, among other fields.

Key topics include: matrices, vectors, simultaneous systems of linear equations, diagonal form, eigenvalues, eigenvectors, projections, points, lines, planes, hyperplanes, rotations, reflections, shears, scaling.

Popular packages for solving linear algebra problems include , , , and .

4466 questions
39
votes
4 answers

Sample from multivariate normal/Gaussian distribution in C++

I've been hunting for a convenient way to sample from a multivariate normal distribution. Does anyone know of a readily available code snippet to do that? For matrices/vectors, I'd prefer to use Boost or Eigen or another phenomenal library I'm not…
JCooper
  • 6,395
  • 1
  • 25
  • 31
39
votes
1 answer

Why does numpy.linalg.solve() offer more precise matrix inversions than numpy.linalg.inv()?

I do not quite understand why numpy.linalg.solve() gives the more precise answer, whereas numpy.linalg.inv() breaks down somewhat, giving (what I believe are) estimates. For a concrete example, I am solving the equation C^{-1} * d where C denotes…
ShanZhengYang
  • 16,511
  • 49
  • 132
  • 234
39
votes
5 answers

Efficient 4x4 matrix inverse (affine transform)

I was hoping someone can point out an efficient formula for 4x4 affine matrix transform. Currently my code uses cofactor expansion and it allocates a temporary array for each cofactor. It's easy to read, but it's slower than it should be. Note,…
Budric
  • 3,599
  • 8
  • 35
  • 38
38
votes
6 answers

Python (NumPy, SciPy), finding the null space of a matrix

I'm trying to find the null space (solution space of Ax=0) of a given matrix. I've found two examples, but I can't seem to get either to work. Moreover, I can't understand what they're doing to get there, so I can't debug. I'm hoping someone might…
Nona Urbiz
  • 4,873
  • 16
  • 57
  • 84
37
votes
8 answers

How expensive is it to compute the eigenvalues of a matrix?

How expensive is it to compute the eigenvalues of a matrix? What is the complexity of the best algorithms? How long might it take in practice if I have a 1000 x 1000 matrix? I assume it helps if the matrix is sparse? Are there any cases where the…
Frank
37
votes
4 answers

Efficient & pythonic check for singular matrix

Working on some matrix algebra here. Sometimes I need to invert a matrix that may be singular or ill-conditioned. I understand it is pythonic to simply do this: try: i = linalg.inv(x) except LinAlgErr as err: #handle it but am not sure…
Dr. Andrew
  • 2,532
  • 3
  • 26
  • 42
36
votes
7 answers

How to create random orthonormal matrix in python numpy

Is there a method that I can call to create a random orthonormal matrix in python? Possibly using numpy? Or is there a way to create a orthonormal matrix using multiple numpy methods? Thanks.
Dacion
  • 471
  • 1
  • 4
  • 8
36
votes
2 answers

Efficient element-wise multiplication of a matrix and a vector in TensorFlow

What would be the most efficient way to multiply (element-wise) a 2D tensor (matrix): x11 x12 .. x1N ... xM1 xM2 .. xMN by a vertical vector: w1 ... wN to obtain a new matrix: x11*w1 x12*w2 ... x1N*wN ... xM1*w1 xM2*w2 ... xMN*wN To give some…
35
votes
7 answers

Matrix power in R

Trying to compute the power of a matrix in R, I found that package expm implements the operator %^%. So x %^% k computes the k-th power of a matrix. > A<-matrix(c(1,3,0,2,8,4,1,1,1),nrow=3) > A %^% 5 [,1] [,2] [,3] [1,] 6469 18038…
gd047
  • 29,749
  • 18
  • 107
  • 146
35
votes
3 answers

Efficient dot products of large memory-mapped arrays

I'm working with some rather large, dense numpy float arrays that currently reside on disk in PyTables CArrays. I need to be able to perform efficient dot products using these arrays, for example C = A.dot(B), where A is a huge (~1E4 x 3E5 float32)…
ali_m
  • 71,714
  • 23
  • 223
  • 298
34
votes
5 answers

What is SVD(singular value decomposition)

How does it actually reduce noise..can you suggest some nice tutorials?
shiva
32
votes
5 answers

Equivalent of `polyfit` for a 2D polynomial in Python

I'd like to find a least-squares solution for the a coefficients in z = (a0 + a1*x + a2*y + a3*x**2 + a4*x**2*y + a5*x**2*y**2 + a6*y**2 + a7*x*y**2 + a8*x*y) given arrays x, y, and z of length 20. Basically I'm looking for the equivalent of…
Justin Gabitzsch
  • 395
  • 1
  • 4
  • 7
32
votes
9 answers

How to find linearly independent rows from a matrix

How to identify the linearly independent rows from a matrix? For instance, The 4th rows is independent.
SparkAndShine
  • 17,001
  • 22
  • 90
  • 134
31
votes
9 answers

Row-major vs Column-major confusion

I've been reading a lot about this, the more I read the more confused I get. My understanding: In row-major rows are stored contiguously in memory, in column-major columns are stored contiguously in memory. So if we have a sequence of numbers [1,…
vexe
  • 5,433
  • 12
  • 52
  • 81
31
votes
1 answer

Most efficient way to solve a system of linear equations

I have an (n x n) symmetric matrix A and a (n x 1) vector B. Basically, I just need to solve Ax = b for x. The issue is that A is going to potentially be massive. So I'm looking for the most efficient algorithm for solving linear equations in…
aesir
  • 565
  • 2
  • 13
  • 23