[Numpy-discussion] Can this be done efficiently with array functions?

Chris Barker chrishbarker at home.net
Fri May 4 14:52:01 EDT 2001


I have a problem that I can't figure otu a non-kludgey way to solve:

Given a (MXN) array, a, I want to compute the minimum value in each row,
excluding the values that are zero. example:

for this array, a:

[[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,]]

I want:

[[5,]
 [0,]
 [5,]
 [0,]
 [1,]
 [0,]
 [2,]
 [0,]]

what I want is minimum.reduce(a,1), except that the zeros would be
ignored. At first glace, Masked arrays seemed the perfect option (as
that's what the zero means, no real data), but there doesn't seem to be
a minimum.reduce() in MA.

By the way, what is the downside to Masked Arrays? they seem to be a
really powerful option. Is there any performance hit to using a masked
array over a regular onw if there is no mask? If not, would it make
sense to move toward just using Masked arrays for everything?

thanks,

-Chris





-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------




More information about the NumPy-Discussion mailing list