What's wrong with this code :
import numpy as np
A = np.array([[-0.5, 0.2, 0.0],
[4.2, 3.14, -2.7]])
asign = lambda t: 0 if t<0 else 1
asign(A)
print(A)
expected out:
[[0. 1. 0.]
[ 1. 1. 0.]]
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
np.array([[-0.5, 0.2, 0.0], [4.2, 3.14, -2.7]]) < 0
to be? Python doesn't know how to handle that kind of comparison. – all or NoneA < 0
. This makes no sense. I think you want smth likeB = [assign(a) for a in x for x in A]
or anything else. – sashaaeroA<0
produces a boolean array the same size asA
. Pythonif
only works with a scalar boolean True/False. It's a simple either/or action. It can't work with multiple boolean values. – hpaulj