linear-algebra


Pseudoinverse calculation in Python

匆匆过客 提交于 2020-02-02 16:22:28
问题 Problem I was working on the problem described here. I have two goals. For any given system of linear equations, figure out which variables have unique solutions. For those variables with unique solutions, return the minimal list of equations such that knowing those equations determines the value of that variable. For example, in the following set of equations X = a + b Y = a + b + c Z = a + b + c + d The appropriate output should be c and d, where X and Y determine c and Y and Z determine d.

Stack numpy array onto diagonal

[亡魂溺海] 提交于 2020-01-30 06:19:07
问题 Given N 2d numpy arrays, is there a neat way in which I can 'stack' or 'bolt' them together on the diagonal, filling any new slots with 0? E.g. given: arr1 = np.array([[1, 2], [3, 4]]) arr2 = np.array([[9, 8, 7], [6, 5, 4], [3, 2, 1]]) I want to create: arr = np.array([[1, 2, 0, 0, 0], [3, 4, 0, 0, 0], [0, 0, 9, 8, 7], [0, 0, 6, 5, 4], [0, 0, 3, 2, 1]]) 回答1: There's a function for that. scipy.linalg.block_diag(arr1, arr2) It takes arbitrarily many parameters: scipy.linalg.block_diag(*list_of

Find all solutions of row reduced echelon matrix in pure python

杀马特。学长 韩版系。学妹 提交于 2020-01-26 02:07:30
问题 I have toggle = [[1, 1, 1, 1, 0, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 1, 1, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]] puzzle = [0, 0, 0, 0, 1, 0, 0, 0, 0] toggle is a matrix I already transformed to [row echelon form] with Gaussian elimination. This is in GF(2) space, which means that -1 = 1 and 1 + 1 = 0 . I already have a working

Find all solutions of row reduced echelon matrix in pure python

妖精的绣舞 提交于 2020-01-26 02:07:22
问题 I have toggle = [[1, 1, 1, 1, 0, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 1, 1, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]] puzzle = [0, 0, 0, 0, 1, 0, 0, 0, 0] toggle is a matrix I already transformed to [row echelon form] with Gaussian elimination. This is in GF(2) space, which means that -1 = 1 and 1 + 1 = 0 . I already have a working

run time error when using a mex file, maybe due to memory allocation

混江龙づ霸主 提交于 2020-01-25 21:24:12
问题 I've written a mex function named mx_minimum_power that I'm calling it in MATLAB as follows: [Fs,Fd,pow_remained] = mx_minimum_power(A11,A12_real,A12_imag,A13_real,A13_imag,A22,A23_real,A23_imag,A33,MatSize); A11, A12_real, A13_real, A22, A23_real, A33 are 30555x1 single matrices A12_imag, A13_imag, A23_imag are 1x1 single variables MatSize is a 1x1 double variable with the value 30555 , that is the size of matrices In an iteration, each time the hermitian matrix A is constructed and

How do I determine whether a 3-dimensional vector is contained within the acute region formed by three other vectors?

孤街醉人 提交于 2020-01-24 22:07:54
问题 I'm working on a project in C# where I have three vectors in R3, and I need to find out if a third vector is contained within the region formed by those vectors. The three basis vectors have a maximum angle of 90 degrees between any two of them, and they are all normalized on the unit sphere. They can be negative. So far, I've tried matrix-vector multiplication to find the transformed coordinates of the vector. From there, I check whether all three components are positive. This method works

How do I determine whether a 3-dimensional vector is contained within the acute region formed by three other vectors?

青春壹個敷衍的年華 提交于 2020-01-24 22:07:33
问题 I'm working on a project in C# where I have three vectors in R3, and I need to find out if a third vector is contained within the region formed by those vectors. The three basis vectors have a maximum angle of 90 degrees between any two of them, and they are all normalized on the unit sphere. They can be negative. So far, I've tried matrix-vector multiplication to find the transformed coordinates of the vector. From there, I check whether all three components are positive. This method works

numpy.array_equal returns False, even though arrays have the same shape and values

£可爱£侵袭症+ 提交于 2020-01-24 15:17:06
问题 I have a very simple function, as shown below def new_price(A, B, x): return np.linalg.inv(A @ B) @ x These are the inputs I give it A = np.array([ [2, 0, 1, 0], [1, 1, 1, 1], [0, 0, 0, 10] ]) B = np.array([ [3, 3, 3], [2, 0, 8], [0, 5, 3], [0, 0, 10] ]) x = np.array([ 84, 149, 500]) This returns the array [ 1. 3. 5.] . But, when I make the following equality check, it returns False v1 = new_price(A, B, x) v2 = np.array([1.0, 3.0, 5.0]) np.array_equal(new_price(A, B, [ 84, 149, 500]), np

numpy.array_equal returns False, even though arrays have the same shape and values

别等时光非礼了梦想. 提交于 2020-01-24 15:16:13
问题 I have a very simple function, as shown below def new_price(A, B, x): return np.linalg.inv(A @ B) @ x These are the inputs I give it A = np.array([ [2, 0, 1, 0], [1, 1, 1, 1], [0, 0, 0, 10] ]) B = np.array([ [3, 3, 3], [2, 0, 8], [0, 5, 3], [0, 0, 10] ]) x = np.array([ 84, 149, 500]) This returns the array [ 1. 3. 5.] . But, when I make the following equality check, it returns False v1 = new_price(A, B, x) v2 = np.array([1.0, 3.0, 5.0]) np.array_equal(new_price(A, B, [ 84, 149, 500]), np

Numpy - Dot Product of a Vector of Matrices with a Vector of Scalars

[亡魂溺海] 提交于 2020-01-24 04:45:09
问题 I have a 3 dimensional data set that I am trying to manipulate in the following way. data.shape = (643, 2890, 10) vector.shape = (643,) I would like numpy to see data as a 643 length 1-D array of 2890x10 matrices and calculate a dot product (sum-product?) between data and vector. I can do this with a loop, but would really like to find a way to do this using a primitive (this will be run many times across parallel nodes). The equivalent loop (I believe): a = numpy.zeros ((2890, 10)) for i in

工具导航Map