I have an numpy ndarray where i want to perform a simple row-wise operation to get a value
new_val = np.where((data['val'][:,0,1,0] > 0 and data['val'][:,0,0,0] > 0), ((data['val'][:,0,1,0] + data['val'][:,0,0,0])/2),\
np.where((data['val'][:,0,1,0] > 0 and data['val'][:,0,0,0] == 0), data['val'][:,0,1,0], \
np.where((data['val'][:,0,0,0] > 0 and data['val'][:,0,1,0] == 0), data['val'][:,0,0,0], 0)))
I get an error stating that I need to use .any or .all. Basically what I want is in the first where condition add both numbers and divide by two. if one of them is 0, then only leave the one where it is not 0. If both are 0 then give zero. How do I achieve this?
I receive the dreaded
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all(). How do i fix this?