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

Home » Public Forums » archive » How multiply two arrays in IDL?
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
How multiply two arrays in IDL? [message #90865] Thu, 30 April 2015 06:47 Go to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello,

I have two arrays as below:

a = [1, 2, 3, 4, 5, 6]
b = [[3, 4, 5, 6, 7, 8], [9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20]]

When I multiply a and b, I get the following

a * b = [3, 8, 15, 24, 35, 48]

instead of the following result

[[3, 8, 15, 24, 35, 48], [9, 20, 33, 48, 65, 84], [15, 32, 51, 72, 95, 120]]

Can anyone suggest me how I can obtain the result as desired?

Thanks in advance,
Madhavan
Re: How multiply two arrays in IDL? [message #90866 is a reply to message #90865] Thu, 30 April 2015 07:54 Go to previous messageGo to next message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
See matrix operators
http://www.exelisvis.com/docs/matrix_operators.html
Re: How multiply two arrays in IDL? [message #90867 is a reply to message #90865] Thu, 30 April 2015 08:39 Go to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
On Thursday, 30 April 2015 06:47:26 UTC-7, Madhavan Bomidi wrote:
> Hello,
>
> I have two arrays as below:
>
> a = [1, 2, 3, 4, 5, 6]
> b = [[3, 4, 5, 6, 7, 8], [9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20]]
>
> When I multiply a and b, I get the following
>
> a * b = [3, 8, 15, 24, 35, 48]
>
> instead of the following result
>
> [[3, 8, 15, 24, 35, 48], [9, 20, 33, 48, 65, 84], [15, 32, 51, 72, 95, 120]]
>
> Can anyone suggest me how I can obtain the result as desired?
>
> Thanks in advance,
> Madhavan

It looks like you want to extend a to match the rows of b, then multiply corresponding elements, like this:

IDL> Rebin(a, [6, 3]) * b
3 8 15 24 35 48
9 20 33 48 65 84
15 32 51 72 95 120

... or generally:
IDL> Rebin(a, Size(b, /DIMENSIONS)) * b
3 8 15 24 35 48
9 20 33 48 65 84
15 32 51 72 95 120

Hope this helps!

-Dick

Dick Jackson Software Consulting Inc.
Victoria, BC, Canada --- http://www.d-jackson.com
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Create folder below certain file
Next Topic: Copying contents of a function graphics window

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

Current Time: Wed Oct 08 07:17:03 PDT 2025

Total time taken to generate the page: 0.00392 seconds