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

Home » Public Forums » archive » Re: Subscripting multidimensional arrays
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: Subscripting multidimensional arrays [message #37284 is a reply to message #37278] Fri, 12 December 2003 06:55 Go to previous messageGo to previous message
Chris Lee is currently offline  Chris Lee
Messages: 101
Registered: August 2003
Senior Member
In article <nwfCb.37807$SU2.20541@newssvr29.news.prodigy.com>, "Jonathan
Greenberg" <greenberg@ucdavis.edu> wrote:


> Hi all -- I was hoping to get some help with converting a vector which
> contains the x,y,z position for a value I want to exract from a
> multidimensional array -- I understand that using an array to subscript
> another array requires knowing the linear subscript position. For
> example: a = 0 10 20
> 30 40 50
> 60 70 80
>
> 90 100 110
> 120 130 140
> 150 160 170
> I have a vector which is defined as:
> locationvector=[2,2,2]
> I want to extract the value at that position (e.g. a[2,2,2] = 170), but
> I can't do a:
> a[locationvector] --> I apparently have to convert the locationvector to
> that linear position. How do I do this? Does IDL have a built in
> function that will do this conversion, or is there an easy formula for
> doing this conversion in ANY dimension? Thanks! --j
>

function element, array, loc_vector

s=size(array)
d=s[1:s[0]] ;dimensions
e=lonarr(s[0]) ;product of dimensions
e[0]=1L
for i=1L, s[0]-1 do e[i]=e[i-1]*d[i-1]
;e is the number of elements each dimension contains
return, total(loc_vector*e)

end


;;test
a=findgen(4,5,6)
;in this example, e=[1,4,20]

b=[2,3,4]
print, a[2,3,4], a[element(a,b)]
94.000 94.000

seems to work, there must be a better way though...

Chris.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: rebinning data on new time samples without loops?
Next Topic: Re: 2D FFT Slow. Any ideas? fft2()

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

Current Time: Sun Oct 12 05:04:38 PDT 2025

Total time taken to generate the page: 1.43314 seconds