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
26
votes
2 answers

Fastest way to compute k largest eigenvalues and corresponding eigenvectors with numpy

I have a large NxN dense symmetric matrix and want the eigenvectors corresponding to the k largest eigenvalues. What's the best way to find them (preferably using numpy but perhaps in general using blas/atlas/lapack if that's the only way to go)? …
Anthony Bak
  • 1,123
  • 3
  • 10
  • 16
25
votes
4 answers

What does data.norm() < 1000 do in PyTorch?

I am following the PyTorch tutorial here. It says that x = torch.randn(3, requires_grad=True) y = x * 2 while y.data.norm() < 1000: y = y * 2 print(y) Out: tensor([-590.4467, 97.6760, 921.0221]) Could someone explain what data.norm()…
bit_scientist
  • 1,496
  • 2
  • 15
  • 34
24
votes
3 answers

Java/Scala library for algebra, mathematics

Can you advise me some flexible and powerful, yet fast library which could cover SciPy (both in performance and functionality). I found SciPy very expressive - but I want to try something in Scala. I read a little about Scala - but is not as…
Robert Zaremba
  • 8,081
  • 7
  • 47
  • 78
24
votes
1 answer

Implementing faster python inner product with BLAS

I found this useful tutorial on using low-level BLAS functions (implemented in Cython) to get big speed improvements over standard numpy linear algebra routines in python. Now, I've successfully gotten the vector product working fine. First I save…
moustachio
  • 2,924
  • 3
  • 36
  • 68
24
votes
2 answers

Link ATLAS/MKL to an installed Numpy

TL;DR how to link ATLAS/MKL to existing Numpy without rebuilding. I have used Numpy to calculate with the large matrix and I found that it is very slow because Numpy only use 1 core to do calculation. After doing a lot of search I figure that my…
tndoan
  • 643
  • 2
  • 6
  • 12
23
votes
2 answers

Linear Algebra library for Javascript?

I don't need anything fancy; basically, if it will let me do some basic Matrix*Matrix stuff I'll be happy.
Xodarap
  • 11,581
  • 11
  • 56
  • 94
23
votes
4 answers

Given Three Points Compute Affine Transformation

I have two images and found three similar 2D points using a sift. I need to compute the affine transformation between the images. Unfortunately, I missed lecture and the information out there is a little dense for me. What would the general method…
23
votes
4 answers

gcc -O0 outperforming -O3 on matrix sizes that are powers of 2 (matrix transpositions)

(For testing purposes) I have written a simple Method to calculate the transpose of a nxn Matrix void transpose(const size_t _n, double* _A) { for(uint i=0; i < _n; ++i) { for(uint j=i+1; j < _n; ++j) { double tmp =…
example
  • 3,349
  • 1
  • 20
  • 29
23
votes
3 answers

Eigen efficient type for dense symmetric matrix

Does Eigen have efficient type for store dense, fixed-size, symmetric matrix? (hey, they are ubiquitous!) I.e. for N=9, it should store only (1+9)*9/2==45 elements and it has appropriate operations. For instance there should be efficient addition of…
qble
  • 1,256
  • 2
  • 12
  • 29
22
votes
7 answers

Algorithm for finding nearby points?

Given a set of several million points with x,y coordinates, what is the algorithm of choice for quickly finding the top 1000 nearest points from a location? "Quickly" here means about 100ms on a home computer. Brute force would mean doing millions…
Bemmu
  • 17,849
  • 16
  • 76
  • 93
22
votes
8 answers

How to check if m n-sized vectors are linearly independent?

Disclaimer This is not strictly a programming question, but most programmers soon or later have to deal with math (especially algebra), so I think that the answer could turn out to be useful to someone else in the future. Now the problem I'm trying…
tunnuz
  • 23,338
  • 31
  • 90
  • 128
22
votes
2 answers

Numpy dot too clever about symmetric multiplications

Anybody know about documentation for this behaviour? import numpy as np A = np.random.uniform(0,1,(10,5)) w = np.ones(5) Aw = A*w Sym1 = Aw.dot(Aw.T) Sym2 = (A*w).dot((A*w).T) diff = Sym1 - Sym2 diff.max() is near machine-precision non-zero, e.g.…
Patrick
  • 1,829
  • 19
  • 32
22
votes
4 answers

Normal equation and Numpy 'least-squares', 'solve' methods difference in regression?

I am doing linear regression with multiple variables/features. I try to get thetas (coefficients) by using normal equation method (that uses matrix inverse), Numpy least-squares numpy.linalg.lstsq tool and np.linalg.solve tool. In my data I have n =…
22
votes
7 answers

Vectorizing a gradient descent algorithm

I am coding gradient descent in matlab. For two features, I get for the update step: temp0 = theta(1,1) - (alpha/m)*sum((X*theta-y).*X(:,1)); temp1 = theta(2,1) - (alpha/m)*sum((X*theta-y).*X(:,2)); theta(1,1) = temp0; theta(2,1) =…
bigTree
  • 2,103
  • 6
  • 29
  • 45
22
votes
1 answer

How to implement MATLAB's mldivide (a.k.a. the backslash operator "\")

I'm currently trying to develop a small matrix-oriented math library (I'm using Eigen 3 for matrix data structures and operations) and I wanted to implement some handy MATLAB functions, such as the widely used backslash operator (which is equivalent…
maddouri
  • 3,737
  • 5
  • 29
  • 51