Using arrays : Failure setting numpy masked object array element with masked array on newest questions tagged arrays – Stack Overflow
This is a little complicated to explain, but I believe it might be a bug in the numpy.ma (masked array) module.
If one has a masked object array (dtype=object) and attempts to set an element of this with a masked array, an error is generated (ValueError: setting an array element with a sequence.). When this happens, the element is actually updated to contain the correct data: the error is obviously occuring in the setting of the mask.
Minimal failing example:
-
Create a masked object array:
moa=ma.array([ma.masked_invalid([1,2,3]), ma.masked_invalid([1,2])])gives:
masked_array(data = [[1 2 3] [1 2]], mask = False, fill_value = ?)moa.dtypegives:
dtype('object') -
Attempt to set an element with a different masked array:
moa[1]=ma.masked_invalid([4,5])gives:
ValueError: setting an array element with a sequence.This is a somewhat contrived example. In my case, I was actually just trying to multiply one of the elements by a certain number, which is essentially replacing it with a new array:
-
Attempt to multiply an element:
moa[1]=moa[1]/10.0gives, as before:
ValueError: setting an array element with a sequence.
Am I misunderstanding something, or is this a legitimate use case for masked arrays?
If not, I’d much appreciate an explanation of why it should not work.
If it indeed should work, I’ll submit a bug report.
source: http://stackoverflow.com/questions/11756585/failure-setting-numpy-masked-object-array-element-with-masked-array
Using arrays : using-arrays
Recent Comments