# 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.

**0**

votes

**0**answers

16 views

### How to solve nC2 variables having n equations?

I want to solve for values where there are nC2 variables and n equations on python using numpy.linalg.lstsq
import numpy as np
x = [[1,1,1,0,0,0],[1,0,0,1,1,0],[0,1,0,1,0,1],[0,0,1,0,1,1]]
y = [1,1,1,...

**1**

vote

**0**answers

31 views

### Avoiding memory allocations with linear algebra calculations in R

As a trivial case, let's say I'm interested in calculating:
r = v*M^t
Where r and v are vectors and M is an extremely large sparse matrix.
I can solve it one of two ways:
r = v*(M*M*M*M...)
r = (((...

**0**

votes

**1**answer

37 views

### python 3 how to use multithreading with numpy linalg norm

I am using python3 with np.linalg.norm to calculate the norms for rows in a matrix (norm(axis=1)), Is there a straightforward way, using only np to make it run using multithreading or multicoring?

**-3**

votes

**1**answer

27 views

### in nueral network , WX+B is linear transformation?

in linear algebra, linear function is called linear transformation
in neural network ,
linear transformation need two condition
f(x+y) = f(x) + f(y)
f(cx) = cf(x)
but WX+B is not satisfied these ...

**2**

votes

**1**answer

67 views

### Left and right eigenvectors in Julia

I have a general real matrix (i.e. not symmetric or Hermitian, etc.), and I would like to find its right eigenvectors and corresponding left eigenvectors in Julia.
Julia's eigen function returns the ...

**0**

votes

**0**answers

39 views

### how to check if vectors inside a matrix are independent?

Im trying to check if a matrix has vectors that are linearly independent or dependent (linear algebra)
I make a first routine that successfully do the revision, but Im interested that in the linearly ...

**-2**

votes

**0**answers

13 views

### For linear endomorphisms A, B given that tr(B) = 1 it is true that tr(AB) < biggest eigenvalue of A. Can you give me a proof for that?

In the density formalism of quantum mechanics B would denote the density matrix and A the projector of the corresponding eigenspace. From tr(AB) I can get the probability of obtaining the ...

**0**

votes

**0**answers

21 views

### How to find euclidean distance from specific camera instead of perpendicular distance from base line in stereo triangulation?

I want to calculate the depth of image pixel in world unit using stereo triangulation principle. Using stereo triangulation principle one get perpendicular distance from base line connecting left and ...

**-1**

votes

**1**answer

47 views

### Linear algebra with a sparse triagonol marix

I have a tridiagonal matrix A which I want to make a sparse matrix and then solve a linear system Ax =b using scipy, how is this done.
i have tried the following code, which dosent work.
from scipy....

**1**

vote

**0**answers

29 views

### Triangular matrix matrix multiply `trmm` in TensorFlow

I need to get fastest possible matmul operation in TF for the case when one of the matrices is lower triangular. The cuBLAS and the BLAS have trmm functions, but looks like TensorFlow doesn't benefit ...

**2**

votes

**0**answers

43 views

### How to plot a 2D plane of set area, using a point on a plane and a normal vector, in 3D space, using plotly and dash?

I would like to plot a 2d plane of a set area (e.g. 10x10 square or 5dia cicle) in 3D space using plotly so I can include it in my dash app. I would also like to be able to rotate and position the ...

**0**

votes

**1**answer

16 views

### How to get a low dimensional rank of non-negative factorization matrix

I have a big matrix
X = numpy.random.rand(1000, 1000)
using sklearn.decomposition I factorized the matrix such as:
from sklearn.decomposition import NMF
model = NMF(n_components=1, init='random', ...

**-1**

votes

**0**answers

16 views

### Looking for ways to transform time-series data recorded from object movement into equation describing the movement direction of the object

Looking for some time-series data transformation advice!
I want to know what's the best way to transform data of 9-tuples time series data of IMU (Inertia Measurement Unit) sensor, recorded from a ...

**0**

votes

**1**answer

43 views

### How can I plot this Octave\Matlab function output?

I everyone,
I am pretty new in Octave\MatLab and I have the following doubt. I have this code calculating a sigmoid function for a parameter z:
function g = sigmoid(z)
%SIGMOID Compute sigmoid ...

**0**

votes

**2**answers

61 views

### Is it possible to start indexing of matrices from 1 in Eigen?

I am using Eigen to do some linear algebra computations in my code. However, all of mathematical formulas are based on the fact that indexing starts from 1. So, each time that I want to implement them ...

**0**

votes

**0**answers

37 views

### Scipy spsolve is order of magnitude slower than matlab mldivide

Ok, so I have a linear system. A is sparse 29791 by 29791 with 202771 stored elements. B is 29791 by 1 with 4561 stored elements.
I have tried solving this system by storing A as csr_matrix and as ...

**0**

votes

**1**answer

42 views

### Export function from mathematica to matlab

Im trying to export a function that draws a heart from mathematica...
Export[NotebookDirectory[] <> "anim1.gif", Table[
Plot[Sqrt[Cos[x]]*Cos[200*x] + Sqrt[Abs[x]] - 0.7*(4 - x*x)^0.01,
{...

**0**

votes

**3**answers

34 views

### What is the best way to append a row to matrix?

I am trying to append a row to a pre-existing matrix. I wrote some code (shown below) that does the trick, but I can't help but feel there is a better way to do this (or perhaps there is already an ...

**1**

vote

**2**answers

84 views

### Speeding Up Kronecker Products Numpy

So I am trying to compute the kronecker product of two matrices each of arbitrary dimension. (I use square matrices of the same dimension just for the examples)
Initially I tried using kron :
a = ...

**3**

votes

**1**answer

87 views

### Confused about Eigen QR decomposition

I am confused about Eigen's QR decomposition. My understanding is that the matrix Q is stored implicitly as a sequence of Householder transformations, and that the matrix R is stored as an upper ...

**1**

vote

**1**answer

33 views

### PyTorch and Chainer implementations of the Linear layer- are they equivalent?

I want to use a Linear, Fully-Connected Layer as one of the input layers in my network. The input has shape (batch_size, in_channels, num_samples). It is based on the Tacotron paper: https://arxiv.org/...

**0**

votes

**1**answer

72 views

### Calculating euclidean distances with Python runs too slow

I read to datasets from file into numpy arrays like this:
def read_data(filename):
data = np.empty(shape=[0, 65], dtype=int)
with open(filename) as f:
for line in f:
data = np....

**0**

votes

**0**answers

26 views

### pyspark distributed linear algebra - possible to compute inverse matrix?

I have two questions:
Is it possible in pyspark to compute the inverse of a real symmetric
positive definite matrix via Cholesky Decomposition, similar to what
is provided in the scala api (I had a ...

**0**

votes

**1**answer

44 views

### how to plot a plane spanned by two vectors in matlab?

I have a matrix, lets say
value = [ 1,0,0;0,1,0]
and need to plot a plane in the space generated by these vectors, something like these:
with the next code
tt=-0.5:0.1:1.5;
ss=-0.5:0.1:1.5;
[s,...

**-3**

votes

**1**answer

2k views

### matrix product of the two tensors [duplicate]

How would you calculate matrix product of the two tensors in PyTorch?
x = torch.Tensor([[1, 2, 3], [1, 2, 3]]).view(-1, 2)
y = torch.Tensor([[2, 1]]).view(2, -1)
I am confused between these ...

**1**

vote

**1**answer

48 views

### X X^T Matrix is not positive definite, although it should be

I have a matrix M where M.shape = (679, 512).
I would like to find the eigenvectors and eigenvalues of M M^T, it's covatiance matrix, which should be positive definite in maths. I find them using:
...

**0**

votes

**1**answer

27 views

### Sympy How To Set Value of every symbol in a list

i have been trying to solve a numerical problem. I used sympy to create symbolic equations such as :
a = symbols('a0:8')
b = symbols('b0:8')
c = symbols('c0:8')
d = symbols('d0:8')
and then i ...

**-1**

votes

**1**answer

37 views

### How to plot all the matrix elements in matlab whitout knowing the size?

Lets say there is the next matrix
A = [ 1 2 2 ;
1 2 3 ;
2 3 4 ;
3 4 5 ;
4 4 6 ;
1 11 12]
I try to use quiver3 to plot the row in the next way:
quiver3(0,0,0,A(1:1),A(1:...

**-2**

votes

**0**answers

38 views

### Octave Coding - Coding to determine a relationship between two matrix

Given an input
1 2 3
0 1 1
1 2 3
1 1 -1
0 1 1
The first 2 lines create a 2 x 3 matrix L while the last 3 lines create a 3 x 3 matrix P.
The first row of L is a point A in L.
The second row of L ...

**-1**

votes

**2**answers

52 views

### Octave Coding - I need help coding coefficients of polynomial

This question fairly easy doing it manually however, I am struggling to have this written in code.
There is a quartic polynomial:
P(x)=ax^4+bx^3+cx^2+dx+e
There is also a given matrix M:
5 0 -1 2 ...

**0**

votes

**1**answer

195 views

### Linear Regression Using Linear Algebra in Python

Am I interpreting these formulas on wikipedia (https://en.wikipedia.org/wiki/Coefficient_of_determination)
wrong in Python? Below is what I have tried.
def ss_res(X, y, theta):
y_diff=[]
...

**0**

votes

**0**answers

42 views

### Calculation of triangle surface normal is off (not perpendicular)

I am trying to simply calculate the surface normal of a triangle made up of 3 points in 3-D space. I'm using the cross product for this, but the results are always off when I plot the vector.
import ...

**0**

votes

**1**answer

39 views

### Solve a Quadratic Equation in two variables using Python

I have got two equations, one linear say,
, where m and c are constants
and the other quadratic say,
, where x1, y1 and r are constants.
Is there a way I can solve for x and y using Python ?
...

**-3**

votes

**0**answers

15 views

### Computing Chebyshev center in R

I am searching for a way to compute the Chebyshev center of a convex polytope, in R.
I would like to have a function of the type:
x0 = chebycenter(A,b);
where x0 is the vector of coordinates of the ...

**0**

votes

**1**answer

76 views

### How to find a new equidistant vector, given five existing vectors?

I have vectors v1, v2, v3, v4, v5, with 100 dim, I need to find a center vector, that will have equal distance with each.
Uptdate: Looking at this answer from Mathmatics, is there a way to implement ...

**0**

votes

**0**answers

26 views

### Calculating Least Squares solution from SVD

I want to calculate the least square solution of a dataset using SVD and I have gotten to the point of collecting the SVD functions
U, s, VT =np.linalg.svd(data[:,:data.shape[1]-1],full_matrices=...

**0**

votes

**1**answer

39 views

### How to add magnitude or value to a vector in Python?

I am using this function to calculate distance between 2 vectors a,b, of size 300, word2vec, I get the distance between 'hot' and 'cold' to be equal 1.
How to add this value (1) to a vector, becz i ...

**-1**

votes

**1**answer

18 views

### Given 2 coordinates, draw a line between them

I have given two coordinates (x1,y1) and (x2,y2) and would like to draw a line between them given a function drawdot(x,y). So to make it look like I draw a line I just want to draw 100 dots between ...

**2**

votes

**0**answers

52 views

### Solving eigenvectors/eigenvalues of sparse matrix in different ranges successively

I'm looking for eigenvalues/eigenvectors of a huge sparse matrix A (250k*250k) that lie in different eigenvalue ranges without calculating all the eigenvalues in between since it would just take too ...

**0**

votes

**0**answers

27 views

### Output from numpy.matrix_power differs from formulaic way of solving

I am supposed to use python to solve a Matrix A^1000. I have tried numpy's built in matrix_power function to compute the output, but when I try to compute the result step by step according to the ...

**1**

vote

**1**answer

59 views

### Using python to solve basic equations [duplicate]

I am trying to solve linear equations using python. Is there any builtin functions or any modules that I can use to achieve my goal or Is there any code written from scratch?
With Thanks,
Roshan

**0**

votes

**1**answer

25 views

### How to fix the plot of the symbolic eigenvalues of the 1st matrix (matlab)?

I'm calculating the eigenvalues of a 8x8-matrix including a symbolic variable "W". Plotting the 8 eigenvalues as functions of W returns a strange result in the plot which looks like someone rode his ...

**1**

vote

**1**answer

49 views

### How to plot eigenvalues representing symbolic functions in Python?

I need to calculate the eigenvalues of an 8x8-matrix and plot each of the eigenvalues for a symbolic variable occuring in the matrix. For the matrix I'm using I get 8 different eigenvalues where each ...

**1**

vote

**1**answer

78 views

### Getting Singular Values of NumPy Data Columns in Order

I would like to calculate the singular value decomposition of a matrix and the order of the singular values is important. By default, it seems numpy.linalg.svd (and scipy.linalg.svd) sort the singular ...

**1**

vote

**1**answer

108 views

### How to performantly sum all products of unordered pairs in a set of binary strings

Given a set of binary strings S, where each binary string has length L, I want to find the sum of all products of unordered pairs of elements in these strings for each unique unordered pair. I then ...

**6**

votes

**1**answer

58 views

### Quaternion division and hyperbolic tangent tanh

Quaternion multiplication is well-defined, and is known to me as "Hamilton product":
// hamilton product
vec4 qmul(in vec4 q1, in vec4 q2) {
return vec4(
q1.w * q2.xyz + q2.w * q1.xyz - ...

**1**

vote

**0**answers

27 views

### Why is the RMSE on the training set decreasing while my matrix completion program is training, and the RMSE on the test set is rising?

I am writing a naive matrix completion program. Curiously, the RMSE on the training set is decreasing during training, but the RMSE on the test set is soaring at first and then slowly decreasing. I ...

**2**

votes

**1**answer

63 views

### How to apply multiple axis rotations on a single rotate3d() call?

I'm trying to use a single rotate3d function to rotate multiple axes of a cube at the same time, but I get a weird rotation.
If I use transform: rotateX(-30deg) rotateY(45deg) I get a nice looking ...

**2**

votes

**1**answer

60 views

### Can camera.lookAt function be calculated from an angle and an axis of rotation, given a target point and the camera forward?

I am trying to understand three.js's camera.lookAt function, and to implement my own.
I'm using eye = camera position, target = target look at point, and up is always (0, 1, 0). A friend proposed ...

**1**

vote

**0**answers

38 views

### How to force python to perform an LU decomposition without a permutation

In MATLAB, it is possible to use a hack to force the builtin LU decomposition algorithm to not use a permutation matrix (i.e., force P=I), as shown here.
Is there a similar hack in python?
Namely, ...