Consider an array:
array([[ 0, 0],
[ 0, 0],
[ 0, 0],
[ 0, 255],
[255, 255],
[255, 255],
[255, 0],
[ 0, 0],
[ 0, 0],
[ 0, 0],
[ 0, 0],
[ 0, 255],
[255, 255],
[255, 0],
[ 0, 0],
[ 0, 0]], dtype=uint8))
I would like to compare this with [255, 0]
and get an output like this:
array([False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
True,
False,
False])
How can I achieve this using numpy, because when I perform arr == [255, 0]
, the shape that I get is (N, 2), meaning it is an element wise comparision:
array([[False, True],
[False, True],
[False, True],
[False, False],
[ True, False],
[ True, False],
[ True, True],
[False, True],
[False, True],
[False, True],
[False, True],
[False, False],
[ True, False],
[ True, True],
[False, True],
[False, True]])
What I tried was to using np.apply_along_axis
function with np.logical_and
, but since the and function takes two arguments, my row is considered as one argument, therefore it gives an invalid argument error:
np.apply_along_axis(lambda x: np.logical_and(x), 1, arr==[255,0])
Value Error: Invalid number of arguments