Re: [Numpy-discussion] Can this be done efficiently with array functions?
Janko and Paul,
Thanks for your suggestions. I had come up with something like Janko's solution, but not as cleanly. It seems that Paul's suggestion is essentially the same thing. Maybe I'll do some tests to see which is faster.
By the way, I tried Janko's code, and got an error on "a == 0" (I'm running Python 2.0). I looked at it again, and then looked at the release notes for Python 2.1, and saw that rich comparisons are working..Glory be! I'll be upgrading real soon, just for that!
thanks again, -Chris
PS: anyone have a response for my Int32 question? Why isn't it a "long" on Linux or windows on Intel?
Janko Hauser wrote:
a=array([[10, 0, 5, 0,], [ 0, 0, 0, 0,], [ 0, 5,15, 0,], [ 0, 0, 0, 0,], [ 0, 3, 1,25,], [ 0, 0, 0, 0,], [ 4, 7, 2,12,], [ 0, 0, 0, 0,]])
am=minimum.reduce(where(a==0,truely_max,a),1) am=where(am==truely_max,0,am) print am [5 0 5 0 1 0 2 0]
"Paul F. Dubois" wrote:
but there doesn't seem to be a minimum.reduce() in MA.
--> I'll add this to my list.
That will be great if you get a chance.
Meanwhile you could do something like this, where x is your array:
y = MA.masked_equal(x,0,copy=0) Numeric.minimum.reduce(y.filled(100000), 1) If x is floating point use masked_value rather than masked_equal.
--> There are two problems. There is a hit, even in the case of no mask. It is hard to quantify because it depends on what operations you do. Much of that could be eliminated if MA was in C but it is Python. It would have driven me mad to write it in C, however.
WOW, I'm impressed, I had assumed that some C was involved. Nice job.
More seriously, there are a few semantic issues where it isn't clear what you mean if a mask is present.
I'm sure these could be resolved. It would be nice if we could have in mind to move in that direction. I'm not going ot be able to do any of the coding, so that's the last you'll here from me about it.