I want to have a boolean numpy array fixidx
that is the result of comparing numpy arrays a
, b
, c
and d
. For example I have the arrays
a = np.array([1, 1])
b = np.array([1, 2])
c = np.array([1, 3])
d = np.array([1, 4])
so the array fixidx
has the values
fixidx = [1, 0]
My approach was
fixidx = (a == b) & (b == c) & (c == d)
This works in Matlab but as it turns out Python only puts out a ValueError.
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
any
or all
won't do the trick or at least I couldn't figure it out.
((a == b) & (b == c) & (c == d)).astype(int)
to get[1,0]
. – Space Impact