matrix-multiplication

Multiply 2 matrices in Javascript

无人久伴 提交于 2019-11-27 22:22:01
I'm doing a function that multiplies 2 matrices. The matrices will always have the same number of rows and columns. (2x2, 5x5, 23x23, ...) When I print it, it doesn't work. Why? For example, if I create two 2x2 matrices: matrixA: [1][2] [3][4] matrixB: [5][6] [7][8] The result should be: [19][22] [43][50] ( http://ncalculators.com/matrix/2x2-matrix-multiplication-calculator.htm ) But, I get: [19][undefined] [22][indefined] function multiplyMatrix(matrixA, matrixB) { var result = new Array();//declare an array //var numColsRows=$("#matrixRC").val(); numColsRows=2; //iterating through first

What is the best matrix multiplication algorithm? [closed]

独自空忆成欢 提交于 2019-11-27 21:27:11
What is the best matrix multiplication algorithm? What means 'the best'for me? It means the fastest and ready for todays machines. Please give links to pseudocode if you can. BLAS is the best ready-to-use efficient matrix multiplication library. There are many different implementation. Here is a benchmark I made for some implementations on a MacBook Pro with dual-core Intel Core 2 Duo 2.66 GHz : gotoBLAS2 (open-source) : https://www.tacc.utexas.edu/research-development/tacc-software/gotoblas2 ATLAS (open-source) : http://math-atlas.sourceforge.net/ Accelerate.framework (Apple) : http:/

How to speed up matrix multiplication in C++?

空扰寡人 提交于 2019-11-27 19:49:46
I'm performing matrix multiplication with this simple algorithm. To be more flexible I used objects for the matricies which contain dynamicly created arrays. Comparing this solution to my first one with static arrays it is 4 times slower. What can I do to speed up the data access? I don't want to change the algorithm. matrix mult_std(matrix a, matrix b) { matrix c(a.dim(), false, false); for (int i = 0; i < a.dim(); i++) for (int j = 0; j < a.dim(); j++) { int sum = 0; for (int k = 0; k < a.dim(); k++) sum += a(i,k) * b(k,j); c(i,j) = sum; } return c; } EDIT I corrected my Question avove! I

Matrix multiplication using arrays

一个人想着一个人 提交于 2019-11-27 19:20:24
I'm trying to make a simple matrix multiplication method using multidimensional arrays ( [2][2] ). I'm kinda new at this, and I just can't find what it is I'm doing wrong. I'd really appreciate any help in telling me what it is. I'd rather not use libraries or anything like that, I'm mostly doing this to learn how it works. Thank you so much in advance. I'm declaring my arays in the main method as follows: Double[][] A={{4.00,3.00},{2.00,1.00}}; Double[][] B={{-0.500,1.500},{1.000,-2.0000}}; A*B should return the identity matrix. It doesn't. public static Double[][] multiplicar(Double[][] A,

2-D convolution as a matrix-matrix multiplication

旧巷老猫 提交于 2019-11-27 17:37:41
I know that, in the 1D case, the convolution between two vectors, a and b , can be computed as conv(a, b) , but also as the product between the T_a and b , where T_a is the corresponding Toeplitz matrix for a . Is it possible to extend this idea to 2D? Given a = [5 1 3; 1 1 2; 2 1 3] and b=[4 3; 1 2] , is it possible to convert a in a Toeplitz matrix and compute the matrix-matrix product between T_a and b as in the 1-D case? Salvador Dali Yes, it is possible and you should also use a doubly block circulant matrix (which is a special case of Toeplitz matrix). I will give you an example with a

numpy elementwise outer product

别来无恙 提交于 2019-11-27 16:06:06
I want to do the element-wise outer product of two 2d arrays in numpy. A.shape = (100, 3) # A numpy ndarray B.shape = (100, 5) # A numpy ndarray C = element_wise_outer_product(A, B) # A function that does the trick C.shape = (100, 3, 5) # This should be the result C[i] = np.outer(A[i], B[i]) # This should be the result A naive implementation can the following. tmp = [] for i in range(len(A): outer_product = np.outer(A[i], B[i]) tmp.append(outer_product) C = np.array(tmp) A better solution inspired from stack overflow. big_outer = np.multiply.outer(A, B) tmp = np.swapaxes(tmp, 1, 2) C_tmp =

Fast sparse matrix multiplication

≯℡__Kan透↙ 提交于 2019-11-27 15:52:58
问题 for class I have to write my own linear equation solver for sparse matrices. I am free to use any type of data structure for sparse matrices and I have to implement several solves, including conjuguate gradient. I was wondering if there is a famous way to store sparse matrices such that multiplication with a vector is relatively fast. Right now my sparse matrices are basically implemented a wrapped std::map< std::pair<int, int>, double> which stores the data, if any. This transforms the

Use a dope vector to access arbitrary axial slices of a multidimensional array?

落爺英雄遲暮 提交于 2019-11-27 15:44:25
I'm building a suite of functions to work with a multidimensional-array data structure and I want to be able to define arbitrary slices of the arrays so I can implement a generalized inner product of two arbitrary matrices (aka Tensors or n-d arrays ). An APL paper I read (I honestly can't find which -- I've read so many) defines the matrix product on left-matrix X with dimensions A;B;C;D;E;F and right-matrix Y with dimensions G;H;I;J;K where F==G as Z <- X +.× Y Z[A;B;C;D;E;H;I;J;K] <- +/ X[A;B;C;D;E;*] × Y[*;H;I;J;K] where +/ is sum of , and × applies element-by-element to two vectors of the

How to optimize matrix multiplication operation [duplicate]

笑着哭i 提交于 2019-11-27 15:13:29
问题 This question already has answers here : Optimized matrix multiplication in C (13 answers) Closed last year . I need to perform a lot of matrix operations in my application. The most time consuming is matrix multiplication. I implemented it this way template<typename T> Matrix<T> Matrix<T>::operator * (Matrix& matrix) { Matrix<T> multipliedMatrix = Matrix<T>(this->rows,matrix.GetColumns(),0); for (int i=0;i<this->rows;i++) { for (int j=0;j<matrix.GetColumns();j++) { multipliedMatrix

Matrix expression causes error “requires numeric/complex matrix/vector arguments”?

不羁岁月 提交于 2019-11-27 14:37:49
ma=diag(3)+t(da)%*%da R Code above, error message as follows: Error in t(da) %*% da : requires numeric/complex matrix/vector arguments da is a matrix, looks as following: V45 V46 V47 V48 V49 V50 V51 1 0.461727059 2.357732985 -1.536932071 -1.34425710 0.893541975 -0.0676913075 -0.86532231 2 0.253022555 1.524473647 -0.588911138 -1.65207275 -0.072255170 -0.5212951533 -1.43686625 3 0.824678362 1.497001189 0.335973892 -0.84027799 0.275289411 -0.2921928001 -0.16277595 4 0.854530787 2.258305198 0.107346531 -1.69194014 -0.841572928 -1.1153931009 -1.939461341 5 1.148286984 -0.232390389 -0.498465734 -0