linear-algebra

How to delete small elements in sparse matrix in Python's SciPy?

How to delete small elements in sparse matrix in Python's SciPy? Question: I have a question that is quite similiar to Sean Laws example that you can find here: https://seanlaw.github.io/2019/02/27/set-values-in-sparse-matrix/ In my case, I want to delete all the elements in a sparse csr matrix, which have an absolute value smaller than some epsilon. First …

Total answers: 2

Change of basis in numpy

Change of basis in numpy Question: Given two basis matrices basis_old and basis_new in numpy, is there a function somewhere in the library to get the transformation matrix to convert a vector vec in basis_old to its representation in basis_new? For example, if I have a vector vec = [1,2,3] in the standard basis [1,0,0], …

Total answers: 1

Rotate covariance matrix

Rotate covariance matrix Question: I am generating 3D gaussian point clouds. I’m using the scipy.stats.multivariate.normal() function, which takes a mean value and a covariance matrix as arguments. It can then provide random samples using the rvs() method. Next I want to perform a rotation of the cloud in 3D, but rather than rotate each point …

Total answers: 1

Vectorize Conway's Game of Life in pure numpy?

Vectorize Conway's Game of Life in pure numpy? Question: I’m wondering if there is a way to implement Conway’s game of life without resorting to for loops, if statements and other control structures typical of programming. It should be pretty easy to vectorize for loops, but how would you convert the checks on the neighborhood …

Total answers: 2

Python linprog minimization–simplex method

Python linprog minimization–simplex method Question: I’m using scipy.optimize.linprog library to calculate the minimization using the simplex method. I’m working on this problem in my textbook and I’m hoping someone can point me in the right direction because I’m not getting the output I expect. The problem is: Minimize w = 10*y1 + 15*y2 + 25*y3 …

Total answers: 3

Understanding tensordot

Understanding tensordot Question: After I learned how to use einsum, I am now trying to understand how np.tensordot works. However, I am a little bit lost especially regarding the various possibilities for the parameter axes. To understand it, as I have never practiced tensor calculus, I use the following example: A = np.random.randint(2, size=(2, 3, …

Total answers: 3

Non-linear Least Squares Fitting (2-dimensional) in Python

Non-linear Least Squares Fitting (2-dimensional) in Python Question: I was wondering what the correct approach to fitting datapoints to a non-linear function should be in python. I am trying to fit a series of data-points t = [0., 0.5, 1., 1.5, …., 4.] y = [6.3, 4.5,……………..] using the following model function f(t, x) = …

Total answers: 3

How to create random orthonormal matrix in python numpy

How to create random orthonormal matrix in python numpy Question: 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. Asked By: Dacion || Source Answers: Version 0.18 of scipy has …

Total answers: 7

Transforming a row vector into a column vector in Numpy

Transforming a row vector into a column vector in Numpy Question: Let’s say I have a row vector of the shape (1, 256). I want to transform it into a column vector of the shape (256, 1) instead. How would you do it in Numpy? Asked By: M.Y. Babt || Source Answers: you can use …

Total answers: 6

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

Efficient element-wise multiplication of a matrix and a vector in TensorFlow Question: 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 … …

Total answers: 1