[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "clamping" an array to a maximum value?




Martin Schultz <mgs@io.harvard.edu> writes:
> Yup,
> 
>    that's what I really intended to say/write. BTW: How about a "last
> element" operator? I very often need something like 
>    subdata = data[*,0:n_elements(data[0,*])-1]
> which is not very aesthetic ;-) is it? It would just be great if one
> could write something like
>    subdata = data[*,0:(*)-1]   or anything with a similar short syntax
> In this case the parantheses would serve to distinguish between "all
> elements" and "last element". That's probably a little dangerous. Anyone
> with a better idea?

Yes, yes, a billion times yes!  A billion is about the number of times
I could have used this capability.

Some present-day scripting languages allow you to supply negative
subscripts, to indicate indexing from the end rather than the front of
the array.  data[-1] would indicate the last element, data[-2] the
second to last, etc.  Powerful, but maybe *too* powerful.

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL: craigmnet@astrog.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------