comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Matrix a*b in loop
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Matrix a*b in loop [message #89043] Thu, 17 July 2014 14:16 Go to next message
Gompie is currently offline  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 Go to previous messageGo to next message
Yngvar Larsen is currently offline  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 Go to previous message
Mats Löfdahl is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to disable tick labels on right and top when using cgMap?
Next Topic: MIN(), MAX() with NaN values

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:51:49 PDT 2025

Total time taken to generate the page: 0.00590 seconds