I look up in a table if keys have associated arrays, or not. By design, my table.__getitem__()
somtimes returns None
rather than KeyError
-s. I would like this value to be either None
, or the numpy array associated with w
.
value = table[w] or table[w.lower()]
# value should be a numpy array, or None
if value is not None:
stack = np.vstack((stack, value))
Only if I go with the above code, and the first lookup is a match, I get :
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
and if I go with value = table[w].any() or table[w.lower()].any()
, then if it's a mismatch, I expectedly bump into :
AttributeError: 'NoneType' object has no attribute 'any'
I must be missing the correct way to do this, how to do ?