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

Home » Public Forums » archive » what is the highest subscript in the array?!?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
what is the highest subscript in the array?!? [message #70774] Thu, 06 May 2010 19:12 Go to next message
munka is currently offline  munka
Messages: 36
Registered: December 2009
Member
Hello team,

I find myself wanting to use the highest subscript in an array and
coding "flux[n_elements(flux)-1]"... I seem to remember seeing a
shortcut on here, and I can't remember what it is.

It's irrelevant, but here is where I most recently used this. This
finds the local maximum in an array.
index=where(flux eq max(flux) and flux ne flux[0] and flux ne
flux[n_elements(flux)-1],ct)

Thanks in advance,

~Bill


PS: Right before I posted this, I searched and I figured that
array[[-1]] should return the highest array value... but it doesn't,
and I'm still stumped.

IDL> array=indgen(10)
IDL> print,array[0]
0
IDL> print,array[9]
9
IDL> print,array[10]
% Attempt to subscript ARRAY with <INT ( 10)> is out of
range.
% Execution halted at: $MAIN$
IDL> print,array[[10]]
9
IDL> print,array[[-1]]
0
IDL> print,array[[-2]]
0
IDL>
Re: what is the highest subscript in the array?!? [message #70847 is a reply to message #70774] Fri, 07 May 2010 19:09 Go to previous messageGo to next message
munka is currently offline  munka
Messages: 36
Registered: December 2009
Member
On May 7, 2:05 pm, pp <pp.pente...@gmail.com> wrote:
>
> Could do something like
>
> nflux=n_elements(flux)
> local_maxima=where((flux[1:nflux-2] ge flux[2:nflux-1]) and
> (flux[1:nflux-2] ge flux[0:nflux-3]))+1
>
> That would give the indexes of all points that are local maxima,
> defined as those larger than or equal to their immediate neighbors.
> Then max() or histogram() may be used to pick the highest maxima,
> depending on what is wanted.


Oh yeah! Is there an easy way to increase the "window" range from
just the points next to the point in question to some larger range?
Re: what is the highest subscript in the array?!? [message #70849 is a reply to message #70774] Fri, 07 May 2010 12:05 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On May 7, 3:46 pm, munka <mynameismu...@gmail.com> wrote:
>> On May 7, 6:20 am, wlandsman <wlands...@gmail.com> wrote:
>> Sorry, that should be
>
>>  dum = max(flux[1:N_elements(flux)-2], c) & index = c+1
>
> That still does not return the LOCAL maximum.  If the max is on the
> edge, it will still return a value
>
> IDL> flux=findgen(10)
> IDL> print,flux
>       0.00000      1.00000      2.00000      3.00000      4.00000
> 5.00000
>       6.00000      7.00000      8.00000      9.00000
> IDL> print,max(flux)
>       9.00000
> IDL> print,max(flux[1:N_elements(flux)-2], c)
>       8.00000
> IDL> print,c+1
>            8

Could do something like

nflux=n_elements(flux)
local_maxima=where((flux[1:nflux-2] ge flux[2:nflux-1]) and
(flux[1:nflux-2] ge flux[0:nflux-3]))+1

That would give the indexes of all points that are local maxima,
defined as those larger than or equal to their immediate neighbors.
Then max() or histogram() may be used to pick the highest maxima,
depending on what is wanted.
Re: what is the highest subscript in the array?!? [message #70850 is a reply to message #70774] Fri, 07 May 2010 11:51 Go to previous messageGo to next message
munka is currently offline  munka
Messages: 36
Registered: December 2009
Member
On May 7, 10:37 am, eddie <eha...@gmail.com> wrote:
>> PS:  Right before I posted this, I searched and  I figured that
>> array[[-1]] should return the highest array value... but it doesn't,
>> and I'm still stumped.
>
> Add a 'u' and it should.  A negative unsigned number "wraps" to
> produce a large number.
>
> IDL> array = indgen(10)
> IDL> print,array[[-1u]]
>        9
> This is similar to Carsten's huge number as an index.  You can use
> array[[-1ull]] if you are concerned that your array might have more
> than a gajillion elements.
>
> Unfortunately this trick only works for the last element, array[[-2u]]
> still returns the last element of the array, not the second to last.
>
> Cheers,
> eddie




IDL> flux=findgen(10)
IDL> print,flux
0.00000 1.00000 2.00000 3.00000 4.00000
5.00000
6.00000 7.00000 8.00000 9.00000
IDL> print,flux[[-1u]]
9.00000
IDL> print,flux[5:*]
5.00000 6.00000 7.00000 8.00000 9.00000





Yes! The -1u works! I think I remembered the "trick" that I was
originally thinking of. It doesn't do what I want it to do, but the
[[-1u]] works!

Thanks for the responses!
~Bill
Re: what is the highest subscript in the array?!? [message #70851 is a reply to message #70774] Fri, 07 May 2010 11:46 Go to previous messageGo to next message
munka is currently offline  munka
Messages: 36
Registered: December 2009
Member
> On May 7, 6:20 am, wlandsman <wlands...@gmail.com> wrote:
> Sorry, that should be
>
>  dum = max(flux[1:N_elements(flux)-2], c) & index = c+1

That still does not return the LOCAL maximum. If the max is on the
edge, it will still return a value



IDL> flux=findgen(10)
IDL> print,flux
0.00000 1.00000 2.00000 3.00000 4.00000
5.00000
6.00000 7.00000 8.00000 9.00000
IDL> print,max(flux)
9.00000
IDL> print,max(flux[1:N_elements(flux)-2], c)
8.00000
IDL> print,c+1
8
Re: what is the highest subscript in the array?!? [message #70852 is a reply to message #70774] Fri, 07 May 2010 08:37 Go to previous messageGo to next message
eddie is currently offline  eddie
Messages: 1
Registered: May 2010
Junior Member
> PS:  Right before I posted this, I searched and  I figured that
> array[[-1]] should return the highest array value... but it doesn't,
> and I'm still stumped.

Add a 'u' and it should. A negative unsigned number "wraps" to
produce a large number.

IDL> array = indgen(10)
IDL> print,array[[-1u]]
9
This is similar to Carsten's huge number as an index. You can use
array[[-1ull]] if you are concerned that your array might have more
than a gajillion elements.

Unfortunately this trick only works for the last element, array[[-2u]]
still returns the last element of the array, not the second to last.

Cheers,
eddie
Re: what is the highest subscript in the array?!? [message #70859 is a reply to message #70774] Fri, 07 May 2010 03:35 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On May 7, 6:20 am, wlandsman <wlands...@gmail.com> wrote:

>
> Not relevant to your main question, but if you care about speed and
> have more than 2 elements than it is faster to write (not tested)
>
>     dum = max(flux[1:N_elements(flux)-1], c) & index = c+1
>

Sorry, that should be

dum = max(flux[1:N_elements(flux)-2], c) & index = c+1
Re: what is the highest subscript in the array?!? [message #70860 is a reply to message #70774] Fri, 07 May 2010 03:20 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On May 6, 10:12 pm, munka <mynameismu...@gmail.com> wrote:

> It's irrelevant, but here is where I most recently used this.  This
> finds the local maximum in an array.
>         index=where(flux eq max(flux) and flux ne flux[0] and flux ne
> flux[n_elements(flux)-1],ct)
>

Not relevant to your main question, but if you care about speed and
have more than 2 elements than it is faster to write (not tested)

dum = max(flux[1:N_elements(flux)-1], c) & index = c+1

--Wayne
Re: what is the highest subscript in the array?!? [message #70861 is a reply to message #70774] Fri, 07 May 2010 02:34 Go to previous messageGo to next message
Carsten Lechte is currently offline  Carsten Lechte
Messages: 124
Registered: August 2006
Senior Member
munka wrote:
> IDL> array=indgen(10)
[...]
> IDL> print,array[[10]]
> 9

Well, your could use lasti = [9223372036854775807LL] to define an "index"
that will give you the last array element in most cases.
(Until someone sets COMPILE_OPT STRICTARRSUBS, at least)

IDL> print, array[lasti]
9

And possibly, God kills a kitten everytime someone uses this abomination.


chl
Re: what is the highest subscript in the array?!? [message #70865 is a reply to message #70774] Thu, 06 May 2010 22:39 Go to previous messageGo to next message
R.G.Stockwell is currently offline  R.G.Stockwell
Messages: 163
Registered: October 2004
Senior Member
"Michael Galloy" <mgalloy@gmail.com> wrote in message
news:hs0518$97o$1@speranza.aioe.org...
> On 5/6/10 8:44 pm, munka wrote:
>
> [snipped]
>
>> Also, clicking on your signature link brings me to "http://
>> www.google.com/www.michaelgalloy.com" :\
>
> Not sure what Google is doing there; it works fine in my newsreader, but
> Google Groups is doing something funky.


that may just be the default action for the poster's browser setup
(i.e. to send a linked string from another program into google).


i assure you: www.google.com/www.michaelgalloy.com does not exist.

Google
Error
Not Found
The requested URL /www.michaelgalloy.com was not found on this server.

I actually get that sometime (strangely enough) if I click a link that
is not found (wireless network lost or whatever), where the secondary
action is to try to fire the string off to a google search.

cheers,
bob
Re: what is the highest subscript in the array?!? [message #77950 is a reply to message #70774] Sat, 15 October 2011 11:57 Go to previous message
Giuseppe Papa is currently offline  Giuseppe Papa
Messages: 27
Registered: February 2010
Junior Member
Have no enough money to buy a car? You not have to worry, because it is possible to receive the <a href="http://goodfinance-blog.com/topics/business-loans">business loans</a> to resolve such problems. Thus get a secured loan to buy all you want.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Plotting 3D array as a 'cloud'
Next Topic: Re: Begin-End matching in IDLDE?

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

Current Time: Wed Oct 08 11:39:47 PDT 2025

Total time taken to generate the page: 0.00715 seconds