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

Home » Public Forums » archive » Re: Referencing elements of array expressions
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: Referencing elements of array expressions [message #3521 is a reply to message #3513] Sun, 05 February 1995 18:10 Go to previous message
steinhh is currently offline  steinhh
Messages: 260
Registered: June 1994
Senior Member
In article <3guag9$nqn@marsupial.jpl.nasa.gov>, "Evan F. Fishbein" <eff@tugh.jpl.nasa.gov> writes:
|>
|> A simple question -- Is is possible to reference elements
|> of array expressions. For example, can the last two lines of
|> the following code:
|>
|> x=findgen(40)/10.0
|> y=cos(2.0*!pi*x)
|> i=where(abs(y) lt 1.0e-5)
|> i=i(0:1)+[-1,1]
|>
|> be combined into one line by accessing the first
|> element of the expression "where(abs(y) lt 1.0e-5)"
|> without placing the vector result in a dumy array variable?
|>

Yes, it's possible:

i = (where(abs(y) lt 1.0e-5))(0:1)+[-1,1]

and in general, you can reference elements of arrays in expressions
by adding parentheses around the array expression, and then the index
in another pair of parentheses:

sub_array = (my_arrayfunc(0.5))(0:5)

I wouldn't recommend it in your example, though, because WHERE might
return a scalar long if no elements match the test, but I often use
it with e.g. N_DIMENSIONS = (SIZE(a))(0)


Stein Vidar
[Message index]
 
Read Message
Read Message
Previous Topic: HELP! Trying to plot 3-D data
Next Topic: Computational Science Conference - cocidann.txt [1/1]

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

Current Time: Fri Oct 10 02:36:10 PDT 2025

Total time taken to generate the page: 1.03818 seconds