|
Re: shorten a vector [message #21627 is a reply to message #21625] |
Fri, 08 September 2000 02:04  |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
Liam Gumley wrote:
>
> Andrew <noymer@my-deja.com> wrote in message
> news:8p9gie$6m5$1@nnrp1.deja.com...
>> What's the easiest way to shorten an array by n units
>> by chopping off the first n elements of the array.
>>
>> E.G: I want to make [ 4 6 7 20 15 ]
>>
>> Into [ 6 7 20 15]. Here n=1.
>
> a =
> n = 1
> print, a[(0 + n):*]
> 6 7 20 15
>
> To make it more general, use n_elements to get the index of the last
> element:
>
> last = n_elements(a) - 1
> n = 1
> print, a[(0 + (n < last)):*]
> 6 7 20 15
> n = 4
> print, a[(0 + (n < last)):*]
> 15
> n = 10
> print, a[(0 + (n < last)):*]
> 15
>
> Cheers,
> Liam.
> http://cimss.ssec.wisc.edu/~gumley
Good. But why 0+ ???
It works also for
print, a[n<last:*]
Martin
--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
|
|
|
Re: shorten a vector [message #21629 is a reply to message #21627] |
Thu, 07 September 2000 19:30  |
Liam E. Gumley
Messages: 378 Registered: January 2000
|
Senior Member |
|
|
Andrew <noymer@my-deja.com> wrote in message
news:8p9gie$6m5$1@nnrp1.deja.com...
> What's the easiest way to shorten an array by n units
> by chopping off the first n elements of the array.
>
> E.G: I want to make [ 4 6 7 20 15 ]
>
> Into [ 6 7 20 15]. Here n=1.
a = [4, 6, 7, 20, 15]
n = 1
print, a[(0 + n):*]
6 7 20 15
To make it more general, use n_elements to get the index of the last
element:
last = n_elements(a) - 1
n = 1
print, a[(0 + (n < last)):*]
6 7 20 15
n = 4
print, a[(0 + (n < last)):*]
15
n = 10
print, a[(0 + (n < last)):*]
15
Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley
|
|
|