Skip to content Skip to sidebar Skip to footer

Numpy Compare Array To Multiple Scalars At Once

Suppose I have an array a = np.array([1,2,3]) and I want to compare it to some scalar; this works fine like a == 2 # [False, True, False] Is there a way I can do such a compariso

Solution 1:

Outer product, except it's equality instead of product:

numpy.equal.outer(scalars, a)

or adjust the dimensions and perform a broadcasted comparison:

scalars[:, None] == a

Post a Comment for "Numpy Compare Array To Multiple Scalars At Once"