[Numpy-discussion] How do I do this?
Fri Aug 29 20:09:25 CDT 2008
Keith Goodman wrote:
>> Alan G Isaac wrote:
>>> Does this do what you want?
>>> idx = np.abs(a)<min_value
>>> a[idx] = min_value
>> Keith Goodman wrote:
>>> If you only have integers then
>>> array([ 1, 2, -5, -1, 0])
>>>>> np.sign(x+1e-16) * np.maximum(np.abs(x), 2)
>>> array([ 2., 2., -5., -2., 2.])
>> that would work, though I like Alan's better.
> I thought -1 should go to -2. If not, then my attempt doesn't work.
arrg! yes, you are quite right -- -1 should go to -2. That's what I get
for trying to get home early before the holiday weekend....
honestly, in this case, it probably doesn't matter much. I'm using this
in my wxPython data-visualization oriented 2-d drawing library:
FloatCanvas. When you zoom out an a rectangle, at some point it gets
very small and disappears. Often that is appropriate. however, in some
users, folks want it to reach a minimum size, say a few pixels, and not
get smaller. The trick is that rectangles can have a height that is
negative due to swapping the y axis to be y-up, rather than y-down, like
it usually is for graphics drawing. So if the user wants a minimum
height of 2, and the rect has a height of -1 after scaling, it should
really get a height of -2. as we're only talking a couple pixels, it
probably doesn't matter, and that's why I didn't notice the error.
Christopher Barker, Ph.D.
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
More information about the Numpy-discussion