From: Paul G. <get...@mi...> - 2000-06-05 16:49:55
|
I have a problem where I need to do matrix multiplication of a 7731x7731 matrix; storing this thing would take over 250 MB of memory, which is more than my machine has. :( However, the matrix is empty except for the main diagonal. Ideally, all that needs to be stored is a single vector 7731 elements long, and then tweak matrix multiplication algorithms to account for this. Are there any facilities in NumPy to do this sort of thing, or do I have to roll my own? Is there a way to effeciently store a very sparse matrix and do standard matrix multiplies? Thanks. -Paul Gettings Dep't of Geology & Geophysics University of Utah -- But Your Honor, they needed killin'. |
From: Herbert L. R. <roi...@ha...> - 2000-06-05 17:10:54
|
Unless I am misunderstanding something, you have a vector, which is the diagonal of a square matrix, and thus contains 7731 elements. You want to multiply it by another vector, which has 7731 columns. Element by element by element multiplication will, I think, give you the result that you want. In matlab you would use the diag command and then use the .* operator to get element by element multiplication. In NumPY you would simply use the * operator to multiply the two vectors. Travis Oliphant has sparse matrix classes that you might want to check out, but I don't see why you would need them for this task. HLR ----- Original Message ----- From: "Paul Gettings" <get...@mi...> To: <num...@li...> Sent: Monday, June 05, 2000 6:49 AM Subject: [Numpy-discussion] Sparse matrices in NumPy? > I have a problem where I need to do matrix multiplication of a 7731x7731 > matrix; storing this thing would take over 250 MB of memory, which is more > than my machine has. :( However, the matrix is empty except for the main > diagonal. Ideally, all that needs to be stored is a single vector 7731 > elements long, and then tweak matrix multiplication algorithms to account for > this. Are there any facilities in NumPy to do this sort of thing, or do I > have to roll my own? Is there a way to effeciently store a very sparse > matrix and do standard matrix multiplies? Thanks. > > -Paul Gettings > Dep't of Geology & Geophysics > University of Utah > -- > But Your Honor, they needed killin'. > > > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > http://lists.sourceforge.net/mailman/listinfo/numpy-discussion > |
From: Paul G. <get...@mi...> - 2000-06-05 17:11:15
|
> But memory is so cheap these days! ;-) I am a grad student, and have no money. :( > > However, the matrix is empty except for the main diagonal. > Multiplying by a diagonalized matrix is just vectorized multiplication: > a 0 0 > 0 b 0 . <x, y, z> = <az, by, cz> > 0 0 c My mistake - I need to multiply the 7731x7731 by a 7731x220 element matrix - square matrix times rectangular matrix, not just 2 diagonal matrices. Otherwise, the problem wouldn't be so hard. :) -- That which does not kill you, didn't try hard enough. |
From: Charles G W. <cg...@fn...> - 2000-06-05 17:24:14
|
Paul Gettings writes: > > > > However, the matrix is empty except for the main diagonal. > > Multiplying by a diagonalized matrix is just vectorized multiplication: > > a 0 0 > > 0 b 0 . <x, y, z> = <az, by, cz> > > 0 0 c > My mistake - I need to multiply the 7731x7731 by a 7731x220 element matrix - > square matrix times rectangular matrix, not just 2 diagonal matrices. > Otherwise, the problem wouldn't be so hard. :) Still it's not so bad, you just need to break the 7731x220 matrix into 220 vectors of length 7731 and multiply each of them by the diagonal "matrix", one at a time, and glue the results back together. The 7731x220 matrix should weigh in at about 6MB, hopefully you have enough memory for this... |
From: Jon S. <js...@wm...> - 2000-06-05 17:25:57
|
I don't know if I am missing something, but: Let's suppose you have A so that A.shape is (7731,). It is diagonal, so, obviously, you don't need to save it all. Just a vector. You also have B, shaped like this: (7731,220) And you want to multiply A*B (the matrix way). I would dare to say that what you really need is C=A[:,NewAxis]*B C will be shaped as (7731,220), which is what you probably need. Jon Saenz. | Tfno: +34 946012470 Depto. Fisica Aplicada II | Fax: +34 944648500 Facultad de Ciencias. \\ Universidad del Pais Vasco \\ Apdo. 644 \\ 48080 - Bilbao \\ SPAIN On Mon, 5 Jun 2000, Paul Gettings wrote: > > But memory is so cheap these days! ;-) > I am a grad student, and have no money. :( > > > > However, the matrix is empty except for the main diagonal. > > Multiplying by a diagonalized matrix is just vectorized multiplication: > > a 0 0 > > 0 b 0 . <x, y, z> = <az, by, cz> > > 0 0 c > My mistake - I need to multiply the 7731x7731 by a 7731x220 element matrix - > square matrix times rectangular matrix, not just 2 diagonal matrices. > Otherwise, the problem wouldn't be so hard. :) > > -- > That which does not kill you, didn't try hard enough. > > > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > http://lists.sourceforge.net/mailman/listinfo/numpy-discussion > |
From: Paul G. <get...@mi...> - 2000-06-05 17:58:45
|
> I would dare to say that what you really need is > C=A[:,NewAxis]*B > C will be shaped as (7731,220), which is what you probably need. Based on a simple (small) test, this is exactly what I want; the result of the NewAxis computation is identical to a matrix multiply of the full-sized matrices. Thanks. Now I just have to read the docs until I understand precisely how and why this works. :) -- 101 USES FOR A DEAD MICROPROCESSOR (62) Fungus trellis |