Re: Make_array() and using arrays as subscripts [message #46856 is a reply to message #46851] |
Mon, 09 January 2006 13:24   |
b_gom
Messages: 105 Registered: April 2003
|
Senior Member |
|
|
I think you're looking for the ARRAY_INDICES function (This will
convert the 1-D indices returned by WHERE into a multidimensional
array), but it would be useful if you gave a more specific example of
your problem. For the details you gave, If you have a (3,344) array and
you only need the first 120 elements, then just use REFORM to change
my_array[good_indices] into a (3,40) array.
But, I think you have a more general problem. The result of your WHERE
call is not guaranteed to always fit into an array of the same
dimensionality as your original array, so
you would have to figure out what to do with 'empty' elements in your
final array.
IDL> x=findgen(3,4,5)
IDL> inds=where(x gt 30)
IDL> inds2=array_indices(x,inds)
IDL> help,inds2
INDS2 LONG = Array[3, 29]
IDL> xind=inds2[0,*]
IDL> yind=inds2[1,*]
IDL> zind=inds2[2,*]
IDL> print,n_elements(uniq(xind,sort(xind)))
3
IDL> print,n_elements(uniq(yind,sort(yind)))
4
IDL> print,n_elements(uniq(zind,sort(zind)))
3
So, we have 29 matches, but if we wanted the result in a 3-D array, we
would have 3*4*3-29=7 empty elements!
Brad
Sheldon wrote:
> Hi everyone,
>
> I have a problem with the function MAKE_ARRAY() that I hope someone can
> help me with.
> I created a string array with the dimension (3, 344) and performed some
> basic assignment operations.
> Now I know that when I am finished with the operations I will perform
> on the array, the length 344 will be too long. Let's say that only the
> first 120 elements will be needed. Now I assigned that entire array the
> string '9999' and then when I am ready to reduce the size of the array
> I used the WHERE() function to find the indices where each element is
> not equal to '9999'. All went well until I form this array-as-subscript
> operation:
>
> my_array = my_array[good_indices]
>
> The dimensions all disappear and all I get is an array with the
> elements equalling the number of elements of good_indices, i.e.,
>
> print, size(my_array,/dimensions)
>
> IDL> 120
>
> Now I have used this type of array-as-subscript before on other types
> of array and I have never had this problem before. Does anyone know why
> this happens or how can I cut my_array without losing my 3 dimensions?
>
> Sincerely,
> Sheldon
|
|
|