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

How does pytorch broadcasting work?

torch.add(torch.ones(4,1), torch.randn(4)) produces a Tensor with size: torch.Size([4,4]). Can someone provide a logic behind this?
aerin
  • 20,607
  • 28
  • 102
  • 140
18
votes
1 answer

Make the matrix multiplication operator @ work for scalars in numpy

In python 3.5, the @ operator was introduced for matrix multiplication, following PEP465. This is implemented e.g. in numpy as the matmul operator. However, as proposed by the PEP, the numpy operator throws an exception when called with a scalar…
18
votes
2 answers

Solving large linear systems with block sparse matrices

I want to solve Ax = b where A is a very large square positive definite symmetric block matrix and x and b are vectors. When I say large I mean for a nxn matrix an n as large as 300,000. Here is an example of a much smaller but representative…
Z boson
  • 32,619
  • 11
  • 123
  • 226
18
votes
2 answers

Mystified by qr.Q(): what is an orthonormal matrix in "compact" form?

R has a qr() function, which performs QR decomposition using either LINPACK or LAPACK (in my experience, the latter is 5% faster). The main object returned is a matrix "qr" that contains in the upper triangular matrix R (i.e. R=qr[upper.tri(qr)]).…
gappy
  • 10,095
  • 14
  • 54
  • 73
18
votes
2 answers

Why is numpy's einsum slower than numpy's built-in functions?

I've usually gotten good performance out of numpy's einsum function (and I like it's syntax). @Ophion's answer to this question shows that - for the cases tested - einsum consistently outperforms the "built-in" functions (sometimes by a little,…
bogatron
  • 18,639
  • 6
  • 53
  • 47
18
votes
1 answer

Exact Large Finite Field Linear Algebra Library (e.g. GF(2^128) / GF(2^256) )

General I'm looking for a library that is able to do exact calculations on large finite fields such as GF(2128)/2128 and GF(2256)/2256. I listed the features that I need and the features that would be cool below. Obviously, the library should be as…
Johannes Weiss
  • 52,533
  • 16
  • 102
  • 136
17
votes
1 answer

numpy on multicore hardware

What's the state of the art with regards to getting numpy to use mutliple cores (on Intel hardware) for things like inner and outer vector products, vector-matrix multiplications etc? I am happy to rebuild numpy if necessary, but at this point I am…
NPE
  • 486,780
  • 108
  • 951
  • 1,012
17
votes
1 answer

Understanding Bilinear Layers

When having a bilinear layer in PyTorch I can't wrap my head around how the calculation is done. Here is a small example where I tried to figure out how it works: In: import torch.nn as nn B = nn.Bilinear(2, 2, 1) print(B.weight) Out: Parameter…
MBT
  • 21,733
  • 19
  • 84
  • 102
17
votes
1 answer

What is the most accurate method in python for computing the minimum norm solution or the solution obtained from the pseudo-inverse?

My goal is to solve: Kc=y with the pseudo-inverse (i.e. minimum norm solution): c=K^{+}y such that the model is (hopefully) high degree polynomial model f(x) = sum_i c_i x^i. I am specially interested in the underdetermined case where we have more…
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
17
votes
1 answer

Matrix exponentiation in Python

I'm trying to exponentiate a complex matrix in Python and am running into some trouble. I'm using the scipy.linalg.expm function, and am having a rather strange error message when I try the following code: import numpy as np from scipy import…
anar
  • 463
  • 2
  • 7
  • 11
17
votes
1 answer

Cholesky decomposition of sparse matrices using permutation matrices

I am interested in the Cholesky decomposition of large sparse matrices. The problem I'm having is that the Cholesky factors are not necessarily sparse (just like the product of two sparse matrices is not necessarily sparse). For example for a matrix…
Z boson
  • 32,619
  • 11
  • 123
  • 226
17
votes
4 answers

Three.js - how do up vectors work with lookAt()?

I'm trying to understand how up vectors and lookAt() work together in three.js. I'm setting the up vector of this axisHelper, so that the Y axis always points at the target geo, which marks the position of the up vector. It works as expected for X…
meetar
  • 7,443
  • 8
  • 42
  • 73
17
votes
2 answers

How to compare vectors approximately in Eigen?

Is there a function in Eigen to compare vectors (matrices) using both relative and absolute tolerance aka numpy.allclose? Standard isApprox fails if one of the vectors is very close to zero.
DikobrAz
  • 3,557
  • 4
  • 35
  • 53
17
votes
6 answers

c++ linear formula simplifying library

What is the best (in terms of simplicity of use and performance) C++/C++11 library which can simplify formulas like the following? (a < 0 && b > 0) || (a < 0 && c > 0) || (a < 0 && c > 1) to (e.g.) a < 0 && (b > 0 || c > 0) I think it is very…
remdezx
  • 2,939
  • 28
  • 49
17
votes
2 answers

Rendering infinitely large plane

I want to render a plane so that it looks as if it goes to infinity in all directions. I want the plane boundary in the distance to be the horizon. Using a simple mesh does not work - the computer can't render infinitely many triangles. Even if…
Violin Yanev
  • 1,507
  • 2
  • 16
  • 23