array referencing problem ... [message #42954] |
Tue, 08 March 2005 08:43  |
Andreas Brunn
Messages: 3 Registered: April 2003
|
Junior Member |
|
|
dear listland
I have a problem referencing a three dimensional array with a two
dimensional mask. One solution I�m well aware of is building a two
dimensional array and copy this in each channel of the three dimensional.
But there must be a more elegant and memory saving method doing this, so i
tried the following and ran in an in my eyes a little bit strange behaviour:
ENVI> a=findgen(5,5,5)
ENVI> ma=where(a le 10)
ENVI> print, (a(*,*,1))(ma)
25.0000 26.0000 27.0000 28.0000 29.0000 30.0000 31.0000 32.0000 33.0000
34.0000 35.0000
thats what I hoped and expected as a result
but if I try the following:
ENVI> (a(*,*,1))(ma) = 2
% Expression must be named variable in this context: <FLOAT Array[5, 5]>.
% Execution halted at: $MAIN$
I only get that error message, where is my mistake ?
Is there a way applying this mask on each of the channels without copying
each channel in a two dimensional array ?
thanx a lot in advance
Andi
|
|
|
Re: array referencing problem ... [message #43036 is a reply to message #42954] |
Wed, 09 March 2005 23:01  |
marc schellens[1]
Messages: 183 Registered: January 2000
|
Senior Member |
|
|
> Here is an article that might help:
>
> http://www.dfanning.com/code_tips/tempvar.html
While this article is still covers the point, its a little bit
outdated:
IDL now correctly complains about the expression.
IDL> p = ptr_new( {a:1, b:2, s:{x:0,y:0, a:[256,256,48]} } )
IDL> ((*p).s.a)[2] = ((*p).s.a)[2] * 4
% Expression must be named variable in this context: <INT
Array[3]>.
% Execution halted at: $MAIN$
But there is still another bug in IDL:
function ret,a
return,a
end
IDL> a=1
IDL> ++(ret(a[0]))
IDL> print,a
1
But this only happens if used as a statement:
IDL> print,++(ret(a[0]))
% Expression must be named variable in this context: <INT (
1)>.
% Execution halted at: $MAIN$
Ah, and did I mention that GDL
(http://gnudatalanguage.sourceforge.net/)
behaves correctly in all cases :-)
Cheers,
marc
|
|
|
Re: array referencing problem ... [message #43045 is a reply to message #42954] |
Tue, 08 March 2005 16:02  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Andreas Brunn writes:
> I have a problem referencing a three dimensional array with a two
> dimensional mask. One solution I�m well aware of is building a two
> dimensional array and copy this in each channel of the three dimensional.
> But there must be a more elegant and memory saving method doing this, so i
> tried the following and ran in an in my eyes a little bit strange behaviour:
>
> ENVI> a=findgen(5,5,5)
> ENVI> ma=where(a le 10)
> ENVI> print, (a(*,*,1))(ma)
> 25.0000 26.0000 27.0000 28.0000 29.0000 30.0000 31.0000 32.0000 33.0000
> 34.0000 35.0000
> thats what I hoped and expected as a result
>
> but if I try the following:
> ENVI> (a(*,*,1))(ma) = 2
> % Expression must be named variable in this context: <FLOAT Array[5, 5]>.
> % Execution halted at: $MAIN$
>
> I only get that error message, where is my mistake ?
Too many parentheses. :-)
Here is an article that might help:
http://www.dfanning.com/code_tips/tempvar.html
> Is there a way applying this mask on each of the channels without copying
> each channel in a two dimensional array ?
I would have a look at the Dimensional Juggling Tutorial:
http://www.dfanning.com/tips/rebin_magic.html
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|