linear-algebra

numpy.linalg.solve with right-hand side of more than three dimensions

风流意气都作罢 提交于 2019-12-25 01:48:38
问题 I'm trying to solve an equation system with a 3x3 matrix a and a right hand side b of arbitrary shape (3, ...) . If b has one or two dimensions, numpy.linalg.solve does the trick. It breaks down for more dimensions though: import numpy a = numpy.random.rand(3, 3) b = numpy.random.rand(3) numpy.linalg.solve(a, b) # okay b = numpy.random.rand(3, 4) numpy.linalg.solve(a, b) # okay b = numpy.random.rand(3, 4, 5) numpy.linalg.solve(a, b) # ERR ValueError: solve: Input operand 1 has a mismatch in

How to vectorize the evaluation of outer product matrix for every row of the 2D matrix? [duplicate]

白昼怎懂夜的黑 提交于 2019-12-25 00:37:35
问题 This question already has answers here : Efficiently compute a 3D matrix of outer products - MATLAB (3 answers) Closed 4 months ago . I am trying to speed the process in evaluation the outer product matrix. I have a 4*n matrix named a . I want to evaluate the outer product matrix for every row of a , by the formula: K = a*a'; If I code this process using a for loop, it is as below: K=zeros(4,4,size(a,2)); for i=1:size(a,2) K(:,:,i) = a(:,i)*a(:,i)'; end I have found another method, using

Cholesky decomposition of large sparse matrices in Java

笑着哭i 提交于 2019-12-24 15:27:24
问题 I want to do Cholesky decomposition of large sparse matrices in Java. Currently I'm using the Parallel Colt library class SparseDoubleCholeskyDecomposition but it's much slower than using my code I wrote in C for dense matrices which I use in java with JNI. For example for 5570x5570 matrices with a non-zero density of 0.25% with SparseDoubleCholeskyDecomposition takes 26.6 seconds to factor and my own code for the same matrix using dense storage only takes 1.12 seconds . However, if I set the

trying to read quadratic program in cplex, get error

ⅰ亾dé卋堺 提交于 2019-12-24 14:53:09
问题 I am trying to load a CPLEX LP file in to CPLEX using the "read" command. I believe that in this problem, I have a set of constraints that are quadratic. But, from what I understand CPLEX will still attempt to solve quadratic programming problems. However, when I try to read it in, I get this error: CPLEX Error 1437: Line 284: Illegal quadratic constraint sense. Is there something special I need to do to read in a quadratic programming problem? NOTE: I am able to load this LP file in to scip

Minimizing error of a formula in MATLAB (Least squares?)

余生颓废 提交于 2019-12-24 13:33:12
问题 I'm not too familiar with MATLAB or computational mathematics so I was wondering how I might solve an equation involving the sum of squares, where each term involves two vectors- one known and one unknown. This formula is supposed to represent the error and I need to minimize the error. I think I'm supposed to use least squares but I don't know too much about it and I'm wondering what function is best for doing that and what arguments would represent my equation. My teacher also mentioned

Solving multiple linear sparse matrix equations: “numpy.linalg.solve” vs. “scipy.sparse.linalg.spsolve”

六月ゝ 毕业季﹏ 提交于 2019-12-24 12:25:33
问题 I have to solve a large amount of linear matrix equations of the type "Ax=B" for x where A is a sparse matrix with mainly the main diagonal populated and B is a vector. My first approach was to use dense numpy arrays for this purpose with numpy.linalg.solve, and it works fine with a (N,n,n)-dimensional array with N being the number of linear matrix equations and n the square matrix dimension. I first used it with a for loop iterating through all equations, which in fact is rather slow. But

Stability of SCIPY.NNLS solution on two overlapping A matrices

人盡茶涼 提交于 2019-12-24 11:41:38
问题 I have the following code: import numpy as np from numpy import array from scipy.optimize import nnls def by_nnls(A=None, B=None): """ Linear programming by NNLS """ #print "NOF row = ", A.shape[0] A = np.nan_to_num(A) B = np.nan_to_num(B) x, rnorm = nnls(A,B) x = x / x.sum() # print repr(x) return x def f(arrA, arrB): """ Check if two matrices overlap""" return not set(map(tuple, arrA)).isdisjoint(map(tuple, arrB)) Basically it runs Linear Programing by using NNLS. By taking matrix A and

Check neighbour pixels Matlab

守給你的承諾、 提交于 2019-12-24 11:28:51
问题 I have a A which is 640x1 cell. where the value of each cell A(i,1) varies from row to row, for example A(1,1) =[] , while A(2,1)=[1] and A(3,1)=[1,2,3] . There is another matrix B of size 480x640, where the row_index (i) of vector A corresponds to the col_index of matrix B . While the cell value of each row in vector A corresponds to the row_index in matrix B . For example, A(2,1)=[1] this means col_2 row_1 in matrix B , while A(3,1)=[1,2,3] means col_3 rows 1,2&3 in matrix B . What I'm

2d cross product definition

筅森魡賤 提交于 2019-12-24 11:17:38
问题 In determine if line segment is inside polygon I noticed the accepted answer has an unusual 2d cross roduct definition of: (u1, u2) x (v1, v2) := (u1 - v2)*(u2 - v1) I have never encountered a definition of the 2d cross product such as this one. Can anyone enlighten me as to where such definition originates from? 回答1: I suggest you to take a look at Exterior Algebra. It generalizes the notion of cross product and determinant. The "Motivation examples" section describing areas in the plane

The smartest way to convert a half vectorization to full matrix back

孤人 提交于 2019-12-24 11:05:12
问题 I've a question regarding to the question mentioned above. I've a large data set. Each row corresponds to one day and the matrix is recorded in a vech form, i.e., by vectorizing the unique upper triangle of the matrix and transposing it into a row vector. I want to transform the whole data set back into the full matrices of each day (observation). A short reproducible example is below: structure(list(X01 = c(5.89378246085557, 5.75461814891448, 8.01511372310818 ), X02 = c(2.04749233527123, 1