Rob Allsopp
Rob Allsopp

Reputation: 3528

Numpy add.at not working with masked array

I'm trying to sum some numbers in a masked array using np.add.at as follows:

acc = np.ma.zeros((1,), dtype=np.float64)
arr = np.ma.masked_array([1.,2.,3.,4.,5.], mask=[0, 1, 0, 0, 0])
np.add.at(acc, [0,0,0,0,0], arr)
assert acc[0] == 13

This fails however. add.at appears to ignore the masking, and acc[0] equals 15, not 13 as expected. Should this work as I'm expecting? Is there an add.at equivalent in numpy.ma I should be using?

Upvotes: 1

Views: 79

Answers (0)

Related Questions