summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/ma/core.py5
-rw-r--r--numpy/ma/tests/test_core.py19
2 files changed, 23 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index b02b175d0..2236c3846 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -639,7 +639,10 @@ class _DomainedBinaryOperation:
if t.any(None):
mb = mask_or(mb, t)
# The following line controls the domain filling
- d2 = np.where(t,self.filly,d2)
+ if t.size == d2.size:
+ d2 = np.where(t,self.filly,d2)
+ else:
+ d2 = np.where(np.resize(t, d2.shape),self.filly, d2)
m = mask_or(ma, mb)
if (not m.ndim) and m:
return masked
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index d59428d58..487f14a1f 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -492,6 +492,25 @@ class TestMaskedArrayArithmetic(TestCase):
assert_equal(np.multiply(x,y), multiply(xm, ym))
assert_equal(np.divide(x,y), divide(xm, ym))
+ def test_divide_on_different_shapes(self):
+ x = arange(6, dtype=float)
+ x.shape = (2,3)
+ y = arange(3, dtype=float)
+ #
+ z = x/y
+ assert_equal(z, [[-1.,1.,1.], [-1.,4.,2.5]])
+ assert_equal(z.mask, [[1,0,0],[1,0,0]])
+ #
+ z = x/y[None,:]
+ assert_equal(z, [[-1.,1.,1.], [-1.,4.,2.5]])
+ assert_equal(z.mask, [[1,0,0],[1,0,0]])
+ #
+ y = arange(2, dtype=float)
+ z = x/y[:,None]
+ assert_equal(z, [[-1.,-1.,-1.], [3.,4.,5.]])
+ assert_equal(z.mask, [[1,1,1],[0,0,0]])
+
+
def test_mixed_arithmetic(self):
"Tests mixed arithmetics."
na = np.array([1])