Array juggling help needed [message #45686] |
Fri, 23 September 2005 05:30  |
Haje Korth
Messages: 651 Registered: May 1997
|
Senior Member |
|
|
Good morning,
I need to expand and an array non-uniformly based on its content. I am
trying to to the following:
input array: [1,5,4,1]
output array should be: [1,0.2,0.2,0.2,0.2,0.2,0.25,0.25,0.25,0.25,1]
Each elements of the input array is basically tuned into
fltarr(inputarray[i])/inputarray[i] and the subarray concatenated. Is there
a way to do this in one step, without using "for" loops and array
concatenation? If not, I can work around this, but knowing for sure that
this doesn't work would at least allow me to stop thinking about this
problem. :-)
To me this looks kind of like a "REPLICATE" for vectors function?
Thanks for your input in advance,
Haje
|
|
|
|
Re: array juggling [message #51163 is a reply to message #45686] |
Wed, 08 November 2006 10:38  |
greg michael
Messages: 163 Registered: January 2006
|
Senior Member |
|
|
I was going to suggest this, but I see JD's is way more concise!
Hi Maike,
If I understand what you've written, you have a mask of 6500 points
that you're interested in out of a grid of 360x181 (=65160), described
by your two vectors latindex, lonindex.
I would:
1. convert this to a 2-d mask:
mask=bytarr(360,181)
mask[lonindex,latindex]=1
2. and use this mask to extract the columns:
find the indices of the elements of the mask which you need:
q=where(mask eq 1)
rearrange the cube into 2d, so that you can use the indices to pick out
the columns:
temp2d=reform(temp3d,360*181,60)
and then extract the columns:
result=temp2d[q,*]
result should be an array of (6500,60)
regards,
Greg
|
|
|
Re: array juggling [message #51166 is a reply to message #45686] |
Wed, 08 November 2006 10:19  |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Wed, 08 Nov 2006 09:38:29 -0800, MA wrote:
> It seems to me I should be able to do something like this instead, and
> avoid the loop:
>
> T=temp3D[lonindex,latindex,*]
s=size(temp3D,/DIMENSIONS)
s1=size(T,/DIMENSIONS)
T=temp3d[rebin(transpose(lon+s[0]*lat),s1) + rebin(lindgen(60)*s[0]*s[1],s1)]
JD
|
|
|