So i'm trying to add 2 numpy masked arrays together. The difficulty is that they have to be added as strings because im trying to get a binary code in the resulting output array. The code below is a simplified version of what i'm trying to do. The mask for both arrays will be the same (In practice these would be way larger arrays, but the idea is the same):
a = np.zeros((3,3))
b = np.ones((3,3))
amask = [[False,True,True],[True, True, False],[False, False , True]]
bmask = [[False,True,True],[True, True, False],[False, False , True]]
a = a.astype('str')
b= b.astype('str')
am = ma.masked_array(a,mask = amask)
bm = ma.masked_array(b, mask = bmask)
x = np.add(am,bm)
I would like the output to be something like :
[['01' -- --],[-- -- '01'],['01', '01' --]]
So it's very important for it to be strings, so they can be added as such.
Running this code however gives me the following error:
numpy.core._exceptions.UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32')) -> None
Which I don't understand since both arrays clearly have the same datatypes in my opinion. Adding them without the string conversion works just fine but doesn't give me the required output. I have run into this error before and tried to look it up but never really understood it. Thanks