How multiply two arrays in IDL? [message #90865] |
Thu, 30 April 2015 06:47  |
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 #90867 is a reply to message #90865] |
Thu, 30 April 2015 08:39  |
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
|
|
|