Matrix a*b in loop [message #89043] |
Thu, 17 July 2014 14:16  |
Gompie
Messages: 76 Registered: August 2012
|
Member |
|
|
Hi,
I have a simple question.
I have two matricies A (696 , 1523854 ) and B (1,696) Matrix .
I wish to have a matrix c whose each row is a product of rows elements of a and b i.e a*b
I can do it in a loop by saying a(:,i)*b but it takes a lot of time because I (~1523854 ) would be very large number. Is it possible to do it in one go.
Thanks
GlanPlot
|
|
|
Re: Matrix a*b in loop [message #89048 is a reply to message #89043] |
Fri, 18 July 2014 01:43   |
Yngvar Larsen
Messages: 134 Registered: January 2010
|
Senior Member |
|
|
The following does the job, but will consume a lot of memory:
C = A*(reform(B))[*,intarr(1523854)]
If memory is a problem, you can also split that operation in a loop, e.g. 1000 or 10000 rows at a time, reducing the number of iterations in the loop. The details are left as an exercise to the reader :)
On Thursday, 17 July 2014 23:16:29 UTC+2, Gompie wrote:
> Hi,
>
> I have a simple question.
>
>
>
> I have two matricies A (696 , 1523854 ) and B (1,696) Matrix .
>
> I wish to have a matrix c whose each row is a product of rows elements of a and b i.e a*b
>
>
>
> I can do it in a loop by saying a(:,i)*b but it takes a lot of time because I (~1523854 ) would be very large number. Is it possible to do it in one go.
>
>
>
> Thanks
>
> GlanPlot
|
|
|
Re: Matrix a*b in loop [message #89052 is a reply to message #89043] |
Sat, 19 July 2014 13:31  |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den torsdagen den 17:e juli 2014 kl. 23:16:29 UTC+2 skrev Gompie:
> Hi,
>
> I have a simple question.
>
>
>
> I have two matricies A (696 , 1523854 ) and B (1,696) Matrix .
>
> I wish to have a matrix c whose each row is a product of rows elements of a and b i.e a*b
>
>
>
> I can do it in a loop by saying a(:,i)*b but it takes a lot of time because I (~1523854 ) would be very large number. Is it possible to do it in one go.
Is this what you want to do?
IDL> a = randomu(seed,696,1523854)
IDL> b = randomu(seed,1,696)
IDL> help,a,b
A FLOAT = Array[696, 1523854]
B FLOAT = Array[1, 696]
IDL> c = a ## b
IDL> help,c
C FLOAT = Array[1, 1523854]
http://www.exelisvis.com/docs/Matrix_Operators.html
http://www.exelisvis.com/docs/matrix_multiply.html
|
|
|