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>
|
|
0
|
|
|
|
Reply
|
mynameismunka (8)
|
5/7/2010 2:12:13 AM |
|
munka <mynameismunka@gmail.com> wrote:
> 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.
You are stuck using that until IDL 8.0 comes out, then you can use -1.
Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
|
|
0
|
|
|
|
Reply
|
Michael
|
5/7/2010 2:26:14 AM
|
|
On May 6, 9:26=A0pm, Michael Galloy <mgal...@gmail.com> wrote:
> munka <mynameismu...@gmail.com> wrote:
> > 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.
>
> You are stuck using that until IDL 8.0 comes out, then you can use -1.
>
> Mike
> --www.michaelgalloy.com
> Research Mathematician
> Tech-X Corporation
:(
-1 doesn't even work.
Also, clicking on your signature link brings me to "http://
www.google.com/www.michaelgalloy.com" :\
|
|
0
|
|
|
|
Reply
|
munka
|
5/7/2010 2:44:54 AM
|
|
On May 6, 10:26=A0pm, Michael Galloy <mgal...@gmail.com> wrote:
> munka <mynameismu...@gmail.com> wrote:
> > 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.
>
> You are stuck using that until IDL 8.0 comes out, then you can use -1.
Really? First of all a[-1] used to be an error and now it won't be.
That could be dangerous change of expectations.
Craig
|
|
0
|
|
|
|
Reply
|
Craig
|
5/7/2010 3:32:48 AM
|
|
On 5/6/10 8:44 pm, munka wrote:
> On May 6, 9:26 pm, Michael Galloy<mgal...@gmail.com> wrote:
>> munka<mynameismu...@gmail.com> wrote:
>>> 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.
>>
>> You are stuck using that until IDL 8.0 comes out, then you can use -1.
>>
>> Mike
>> --www.michaelgalloy.com
>> Research Mathematician
>> Tech-X Corporation
>
> :(
> -1 doesn't even work.
>
> Also, clicking on your signature link brings me to "http://
> www.google.com/www.michaelgalloy.com" :\
You need IDL 8.0:
IDL> a = findgen(10)
IDL> print, a[-1]
9.00000
IDL> print, a[-2]
8.00000
Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
|
|
0
|
|
|
|
Reply
|
Michael
|
5/7/2010 4:21:52 AM
|
|
Craig Markwardt writes:
> Really? First of all a[-1] used to be an error and now it won't be.
> That could be dangerous change of expectations.
Yeah, well, IDL 8.0 looks like a dangerous change of
expectations to me. And I mean that in a happy sort
of way. ;-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
0
|
|
|
|
Reply
|
David
|
5/7/2010 4:22:15 AM
|
|
On 5/6/10 9:32 pm, Craig Markwardt wrote:
> On May 6, 10:26 pm, Michael Galloy<mgal...@gmail.com> wrote:
>> munka<mynameismu...@gmail.com> wrote:
>>> 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.
>>
>> You are stuck using that until IDL 8.0 comes out, then you can use -1.
>
> Really? First of all a[-1] used to be an error and now it won't be.
> That could be dangerous change of expectations.
>
> Craig
It does not change valid existing behavoir:
IDL> print, a[[-1]]
0.00000
It would just change conditions which would have caused errors before.
So code that caught the out-of-bounds runtime error instead of just
checking the index will break.
Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
|
|
0
|
|
|
|
Reply
|
Michael
|
5/7/2010 4:27:47 AM
|
|
IDL Version 6.2 (linux x86 m32). (c) 2005, Research Systems, Inc.
Maybe I'll convince the college that I go to to upgrade.... but until
then, I'm stuck with 6.2....
On an unrelated note, check out this cool picture!
http://img.photobucket.com/albums/v461/munka123/M101.png
|
|
0
|
|
|
|
Reply
|
munka
|
5/7/2010 4:29:06 AM
|
|
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.
Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
|
|
0
|
|
|
|
Reply
|
Michael
|
5/7/2010 4:30:31 AM
|
|
"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
|
|
0
|
|
|
|
Reply
|
R
|
5/7/2010 5:39:37 AM
|
|
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
|
|
0
|
|
|
|
Reply
|
Carsten
|
5/7/2010 9:34:48 AM
|
|
On May 6, 10:12=A0pm, munka <mynameismu...@gmail.com> wrote:
> It's irrelevant, but here is where I most recently used this. =A0This
> finds the local maximum in an array.
> =A0 =A0 =A0 =A0 index=3Dwhere(flux eq max(flux) and flux ne flux[0] and f=
lux 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 =3D max(flux[1:N_elements(flux)-1], c) & index =3D c+1
--Wayne
|
|
0
|
|
|
|
Reply
|
wlandsman
|
5/7/2010 10:20:09 AM
|
|
On May 7, 6:20=A0am, 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)
>
> =A0 =A0 dum =3D max(flux[1:N_elements(flux)-1], c) & index =3D c+1
>
Sorry, that should be
dum =3D max(flux[1:N_elements(flux)-2], c) & index =3D c+1
|
|
0
|
|
|
|
Reply
|
wlandsman
|
5/7/2010 10:35:23 AM
|
|
> PS: =A0Right before I posted this, I searched and =A0I 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 =3D 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
|
|
0
|
|
|
|
Reply
|
eddie
|
5/7/2010 3:37:40 PM
|
|
> On May 7, 6:20=A0am, wlandsman <wlands...@gmail.com> wrote:
> Sorry, that should be
>
> =A0dum =3D max(flux[1:N_elements(flux)-2], c) & index =3D 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=3Dfindgen(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
|
|
0
|
|
|
|
Reply
|
munka
|
5/7/2010 6:46:55 PM
|
|
On May 7, 10:37=A0am, eddie <eha...@gmail.com> wrote:
> > PS: =A0Right before I posted this, I searched and =A0I 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. =A0A negative unsigned number "wraps" to
> produce a large number.
>
> IDL> array =3D indgen(10)
> IDL> print,array[[-1u]]
> =A0 =A0 =A0 =A09
> This is similar to Carsten's huge number as an index. =A0You 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=3Dfindgen(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
|
|
0
|
|
|
|
Reply
|
munka
|
5/7/2010 6:51:55 PM
|
|
On May 7, 3:46=A0pm, munka <mynameismu...@gmail.com> wrote:
> > On May 7, 6:20=A0am, wlandsman <wlands...@gmail.com> wrote:
> > Sorry, that should be
>
> > =A0dum =3D max(flux[1:N_elements(flux)-2], c) & index =3D c+1
>
> That still does not return the LOCAL maximum. =A0If the max is on the
> edge, it will still return a value
>
> IDL> flux=3Dfindgen(10)
> IDL> print,flux
> =A0 =A0 =A0 0.00000 =A0 =A0 =A01.00000 =A0 =A0 =A02.00000 =A0 =A0 =A03.00=
000 =A0 =A0 =A04.00000
> 5.00000
> =A0 =A0 =A0 6.00000 =A0 =A0 =A07.00000 =A0 =A0 =A08.00000 =A0 =A0 =A09.00=
000
> IDL> print,max(flux)
> =A0 =A0 =A0 9.00000
> IDL> print,max(flux[1:N_elements(flux)-2], c)
> =A0 =A0 =A0 8.00000
> IDL> print,c+1
> =A0 =A0 =A0 =A0 =A0 =A08
Could do something like
nflux=3Dn_elements(flux)
local_maxima=3Dwhere((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.
|
|
0
|
|
|
|
Reply
|
pp
|
5/7/2010 7:05:50 PM
|
|
On May 7, 2:05=A0pm, pp <pp.pente...@gmail.com> wrote:
>
> Could do something like
>
> nflux=3Dn_elements(flux)
> local_maxima=3Dwhere((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?
|
|
0
|
|
|
|
Reply
|
munka
|
5/8/2010 2:09:23 AM
|
|
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.
|
|
0
|
|
|
|
Reply
|
ErinBattle22
|
10/15/2011 6:56:56 PM
|
|
|
19 Replies
1326 Views
(page loaded in 0.273 seconds)
|