Reputation: 962
I have
A = numpy.array([[ 0.52241976, 0.50960677, 0.34597965]])
B = numpy.array([[0.5, 0.5, 0.5]])
I am looking for a C that does
if (A > B):
C[i] = 1
Expected C: [[ 1, 1, 0]]
How do I do that?
Edit: I have started python today. So I am early beginner in Python
Upvotes: 1
Views: 42
Reputation: 14399
For this specific case you could just do
(A > B).astype(int)
As booleans convert to int
as 0
and 1
Upvotes: 0
Reputation: 14106
np.where
is made for this purpose
C = numpy.where(A > B, 1, 0)
Upvotes: 3