subscribing 3D arrays [message #17135] |
Thu, 16 September 1999 00:00 |
Tom Wassenaar
Messages: 15 Registered: August 1998
|
Junior Member |
|
|
I can't figure out how to directly subscribe a group of individual cells
in one layer of a 3D array. Because of memory problems due to the array
size I do not want to create additional 2D arrays to be assigned later
on to layers of the 3D array.
To illustrate:
a = indgen(3,3)
a[[1,2],[2,1]] = 0
print, a
0 1 2
3 4 0
6 0 8
so 2 cells set to zero, but
b = indgen(3,3,3)
b[[1,2],[2,1],0] = 0
print, b[*,*,0]
0 1 2
3 0 0
6 0 0
so a square envelope of cells set to zero
Any suggestion ?
--
���������� ���������� ���������� ���������� ����
Tom Wassenaar
INRA Science du Sol, 2 place Pierre Viala
34060 Montpellier Cedex 02, tel. +33 (0)499612764
fax +33(0)467632614, M�l : wassenaar@ensam.inra.fr
���������� ���������� ���������� ���������� ����
|
|
|
Re: subscribing 3D arrays [message #17273 is a reply to message #17135] |
Thu, 16 September 1999 00:00  |
fireman
Messages: 49 Registered: August 1991
|
Member |
|
|
Tom Wassenaar (wassenaa@ensam.inra.fr) wrote:
: I can't figure out how to directly subscribe a group of individual cells
: in one layer of a 3D array.
: b = indgen(3,3,3)
: b[[1,2],[2,1],0] = 0
: print, b[*,*,0]
: 0 1 2
: 3 0 0
: 6 0 0
Tom -
Combining subscript arrays and scalars is not as obvious as it seems!
In fact your 2-d example worked only because of the particular subscripts
you chose. See the IDL Manual, Combining Array Subscripts with Others.
I would stick with explicit point reference, as follows:
IDL> b[[1,2,0],[2,1,0]] = 0
IDL> print, b[*,*,0]
0 1 2
3 4 0
6 0 8
Good luck,
Gwyn
--
-- Gwyn F. Fireman
-- General Sciences Corporation / MODIS Characterization Support Team
-- Gwyn.Fireman@gsfc.nasa.gov 301-352-2118
|
|
|
Re: subscribing 3D arrays [message #17274 is a reply to message #17135] |
Thu, 16 September 1999 00:00  |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
Tom Wassenaar wrote:
>
> I can't figure out how to directly subscribe a group of individual cells
> in one layer of a 3D array.
>
> [...]
>
> b = indgen(3,3,3)
> b[[1,2],[2,1],0] = 0
> print, b[*,*,0]
>
> 0 1 2
> 3 0 0
> 6 0 0
>
> so a square envelope of cells set to zero
> Any suggestion ?
When the arrays of index values are of different lengths, IDL takes the subset
of each dimension separately. When you say b[[1,2],[2,1],0], this means all
points with X=1 or 2, Y=2 or 1, and Z=0: 2*2*1 = 4 array elements
What you want to do is give three equal-length arrays, one for each dimension.
Then IDL will take one array element for each corresponding set of three index
values:
b = indgen(3,3,3)
b[[1,2],[2,1],[0,0]] = 0
print, b[*,*,0]
0 1 2
3 4 0
6 0 8
The Replicate command can be useful for making an array of '0' values as long
as you need it.
Cheers,
--
-Dick
Dick Jackson Fanning Software Consulting, Canadian Office
djackson@dfanning.com Calgary, Alberta Voice/Fax: (403) 242-7398
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|