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

Home » Public Forums » archive » Re: simple array math question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: simple array math question [message #33670] Sun, 19 January 2003 22:55 Go to previous message
marc schellens[1] is currently offline  marc schellens[1]
Messages: 183
Registered: January 2000
Senior Member
Jeff Guerber wrote:
> On 16 Jan 2003, Craig Markwardt wrote:
>
>
>> Heinz Stege <reply_to_posting@arcor.de> writes:
>>
>>> On Thu, 16 Jan 2003 14:05:27 -0600, "Sean Raffuse" <sean@me.wustl.edu>
>>> wrote:
>>>
>>>
>>>> >>a=[[1,2,3],[4,5,6],[7,8,9]]
>>>> >
>>>> >>b=[1,2,3]
>>>> >
>>>> What is the best (read, fastest) way to multiply b by each individual row of
>>>> a? I would like to return a result of:
>>>>
>>>> [[1,4,9],[4,10,18],[7,14,27]]
>>>
>>>
>>> result=a*b(*,intarr(3))
>>
>> WOW! I've never seen that! It scares me how cool that is. :-)
>>
>> Craig
>
>
> That IS way cool, but, uhhh, would someone mind explaining just what's
> going on? I'm not getting it. It seems to only depend on the total
> number of elements in the indexing array, not on its values (or even
> dimensionality):
>
> IDL> b=[4,5,6]
> IDL> print,b[*,[10,10,10]]
> 4 5 6
> 4 5 6
> 4 5 6
> IDL> print,b[*,[1000,1000]]
> 4 5 6
> 4 5 6
> IDL> print,b[*,[[10,10,10],[10,10,10]]]
> 4 5 6
> 4 5 6
> 4 5 6
> 4 5 6
> 4 5 6
> 4 5 6
> IDL> help,b[*,[[10,10,10],[10,10,10]]]
> <Expression> INT = Array[3, 6]
> IDL>
>
> Oh, you can apply it multiple times, too:
>
> IDL> print,b[*,[10,10,10,10],[10,10]]
> 4 5 6
> 4 5 6
> 4 5 6
> 4 5 6
>
> 4 5 6
> 4 5 6
> 4 5 6
> 4 5 6
> IDL> help,b[*,[10,10,10,10],[10,10]]
> <Expression> INT = Array[3, 4, 2]
> IDL>
>
If you index an array in IDL with another array,
IDL always eats it, and sets the index to the bounds of the
array.

e.g:
IDL> print,indgen(5)-1
-1 0 1 2 3
IDL> a=indgen(3)
IDL> print,a[indgen(5)-1]
0 0 1 2 2

so the result is:
a[0], a[0], a[1], a[2], a[2]

this works for all dimensions, so in you case
b[*,[10,10,10,10],[10,10]]

is the same as

b[*,[0,0,0,0],[0,0]]

because b is
B INT = Array[3]

which is in IDL the same as:
Array[3,0,0,0,0,0,0,0]

hope that helped,
marc
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: MOUSE (WHEEL) BUTTON NON-STOP SCROLLING IN IDL 5.6
Next Topic: Re: Windows XP graphics problem

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

Current Time: Wed Oct 08 13:34:21 PDT 2025

Total time taken to generate the page: 0.00497 seconds