diff options
author | sasha <sasha@localhost> | 2006-03-05 18:11:38 +0000 |
---|---|---|
committer | sasha <sasha@localhost> | 2006-03-05 18:11:38 +0000 |
commit | fe076fbbda80b494d6b0cde4511df83bddcddfe0 (patch) | |
tree | 96608053ed3c9ad024fa0a64374c909028432acb /numpy/core | |
parent | d5c0229e1ac366b43bc35c9fdbf6d0f102d00539 (diff) | |
download | numpy-fe076fbbda80b494d6b0cde4511df83bddcddfe0.tar.gz |
fixed ma.nonzero
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/ma.py | 9 | ||||
-rw-r--r-- | numpy/core/tests/test_ma.py | 7 |
2 files changed, 14 insertions, 2 deletions
diff --git a/numpy/core/ma.py b/numpy/core/ma.py index 26631693b..7105a4e65 100644 --- a/numpy/core/ma.py +++ b/numpy/core/ma.py @@ -464,7 +464,14 @@ tanh = masked_unary_operation(umath.tanh) absolute = masked_unary_operation(umath.absolute) fabs = masked_unary_operation(umath.fabs) negative = masked_unary_operation(umath.negative) -nonzero = masked_unary_operation(oldnumeric.nonzero) + +def nonzero(a): + """returns the indices of the elements of a which are not zero and not masked + + a must be 1d + """ + return asarray(filled(a,0).nonzero()) + around = masked_unary_operation(oldnumeric.round_) floor = masked_unary_operation(umath.floor) ceil = masked_unary_operation(umath.ceil) diff --git a/numpy/core/tests/test_ma.py b/numpy/core/tests/test_ma.py index a25f9dbf8..58b357528 100644 --- a/numpy/core/tests/test_ma.py +++ b/numpy/core/tests/test_ma.py @@ -690,7 +690,12 @@ class test_ufuncs(ScipyTestCase): self.failUnless((amask.min(0) == [5,6,7,8]).all()) self.failUnless(amask.max(1)[0].mask) self.failUnless(amask.min(1)[0].mask) - + + def test_nonzero(self): + for t in "?bhilqpBHILQPfdgFDGO": + x = array([1,0,2,0], mask=[0,0,1,1]) + self.failUnless(eq(nonzero(x), [0])) + def eqmask(m1, m2): if m1 is nomask: return m2 is nomask |