comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: "clamping" an array to a maximum value?

Re: "clamping" an array to a maximum value?
type: item
description: Kevin Ivory (Kevin@Ivory.de) writes: > Martin Schultz wrote: >> ... but be careful to use parantheses when you want to clamp min and >> max at the same time: >> twoodle_array = (twoodle_array < max_val ) > min_val > > In that case I don't use parantheses either, because I think the > following "looks" nicer: ;-) > > twoodle_array = min_val > twoodle_array < max_val I agree with Kevin. Having nice looking programs is as important as having programs that work correctly. :-) The only problem with Kevin's approach is that I am usually clamping from some mininum value to some maximun-minus-one value. And this definitely does NOT do what you want: twoodle_array = min_val > twoodle_array < max_val - 1 I've been bit so many times with this that I've given up all aesthetics and wrap those damn parentheses around anything that moves. :-( Happy Holidays, David -- David Fanning, Ph.D. Fanning Software Consulting Phone: 970-221-0438 E-Mail: davidf@dfanning.com Coyote's Guide to IDL Progamming: http://www.dfanning.com/ Toll-Free IDL Book Orders: 1-888-461-0155
creator: davidf
date: 1998-12-21T08:00:00-00:00

Re: "clamping" an array to a maximum value?
type: item
description: Martin Schultz wrote: > ... but be careful to use parantheses when you want to clamp min and > max at the same time: > twoodle_array = (twoodle_array < max_val ) > min_val In that case I don't use parantheses either, because I think the following "looks" nicer: ;-) twoodle_array = min_val > twoodle_array < max_val Have nice holidays, Kevin -- Kevin Ivory Tel: +49 5556 979 434 Max-Planck-Institut fuer Aeronomie Fax: +49 5556 979 240 Max-Planck-Str. 2 mailto:Kevin@Ivory.de D-37191 Katlenburg-Lindau, GERMANY http://ivory.de/
creator: Kevin Ivory
date: 1998-12-21T08:00:00-00:00

Re: "clamping" an array to a maximum value?
type: item
description: Kevin Ivory wrote: > dEdmundson@Bigfoot.com wrote: >> I have a 2d array of floats. All elements having >> a value greater than max_val I want to set equal >> to max_val. My solution is a rather complicated- >> looking use of the "where" function. > > That's easy: > twod_array = twod_array < max_val > > Kevin > -- > Kevin Ivory Tel: +49 5556 979 434 > Max-Planck-Institut fuer Aeronomie Fax: +49 5556 979 240 > Max-Planck-Str. 2 mailto:Kevin@Ivory.de > D-37191 Katlenburg-Lindau, GERMANY http://ivory.de/ ... but be careful to use parantheses when you want to clamp min and max at the same time: twoodle_array = (twoodle_array < max_val ) > min_val Martin. -- ------------------------------------------------------------ ------- Dr. Martin Schultz Department for Engineering&Applied Sciences, Harvard University 109 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA phone: (617)-496-8318 fax : (617)-495-4551 e-mail: mgs@io.harvard.edu Internet-homepage: http://www-as.harvard.edu/people/staff/mgs/ ------------------------------------------------------------ -------
creator: Martin Schultz
date: 1998-12-21T08:00:00-00:00

Re: "clamping" an array to a maximum value?
type: item
description: dEdmundson@Bigfoot.com wrote: > I have a 2d array of floats. All elements having > a value greater than max_val I want to set equal > to max_val. My solution is a rather complicated- > looking use of the "where" function. That's easy: twod_array = twod_array < max_val Kevin -- Kevin Ivory Tel: +49 5556 979 434 Max-Planck-Institut fuer Aeronomie Fax: +49 5556 979 240 Max-Planck-Str. 2 mailto:Kevin@Ivory.de D-37191 Katlenburg-Lindau, GERMANY http://ivory.de/
creator: Kevin Ivory
date: 1998-12-21T08:00:00-00:00

Re: "clamping" an array to a maximum value?
type: item
description: dEdmundson@Bigfoot.com wrote in message <75l3vi$nit$1@nnrp1.dejanews.com>... > > > It's late here in Oz and my brain refuses to find an > easy solution to the following seemingly trivial > problem: > > I have a 2d array of floats. All elements having > a value greater than max_val I want to set equal > to max_val. My solution is a rather complicated- > looking use of the "where" function. a = a < maxval where a is the array, should do it... cheers, Mark
creator: Mark Buckley
date: 1998-12-21T08:00:00-00:00

Re: "clamping" an array to a maximum value?
type: item
description: 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 ------------------------------------------------------------ --------------
creator: Craig Markwardt
date: 1998-12-22T08:00:00-00:00

Re: "clamping" an array to a maximum value?
type: item
description: David Fanning wrote: > > Kevin Ivory (Kevin@Ivory.de) writes: > >> Martin Schultz wrote: >>> ... but be careful to use parantheses when you want to clamp min and >>> max at the same time: >>> twoodle_array = (twoodle_array < max_val ) > min_val >> >> In that case I don't use parantheses either, because I think the >> following "looks" nicer: ;-) >> >> twoodle_array = min_val > twoodle_array < max_val > > I agree with Kevin. Having nice looking programs is as important > as having programs that work correctly. :-) > > The only problem with Kevin's approach is that I am usually > clamping from some mininum value to some maximun-minus-one > value. And this definitely does NOT do what you want: > > twoodle_array = min_val > twoodle_array < max_val - 1 > > I've been bit so many times with this that I've given up > all aesthetics and wrap those damn parentheses around anything > that moves. :-( > > Happy Holidays, > > David > -- 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? Happy holidays, Martin. -- ------------------------------------------------------------ ------- Dr. Martin Schultz Department for Engineering&Applied Sciences, Harvard University 109 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA phone: (617)-496-8318 fax : (617)-495-4551 e-mail: mgs@io.harvard.edu Internet-homepage: http://www-as.harvard.edu/people/staff/mgs/ ------------------------------------------------------------ -------
creator: Martin Schultz
date: 1998-12-22T08:00:00-00:00

Re: "clamping" an array to a maximum value?
type: item
description: Martin Schultz wrote: > BTW: How about a "last element" operator? I very often need something like > subdata = data[*,0:n_elements(data[0,*])-1] Just for completeness: that's probably supposed to be subdata = data[*,0:n_elements(data[0,*])-2] Otherwise your problem is trivial and you might as well write subdata = data Sorry, no better idea for the original problem, though. Everything I can think of at the moment is even more complicated. :-( (Or equivalent: n_elements(data[0,*]) is the same as (size(data))[2] which admittedly is not much clearer.) Happy holidays, Kevin -- Kevin Ivory Tel: +49 5556 979 434 Max-Planck-Institut fuer Aeronomie Fax: +49 5556 979 240 Max-Planck-Str. 2 mailto:Kevin@Ivory.de D-37191 Katlenburg-Lindau, GERMANY http://ivory.de/
creator: Kevin Ivory
date: 1998-12-23T08:00:00-00:00