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 ?
if table[w] is not None: ... elif table[w.lower()] is not None: ... else, if possible.v = a or braises theValueErrorifais an array (not ifaisNoneandbis an array though)None..." when do you want it to be None? "or the numpy array associated withw" What's the associated array?table[w]?table[w.lower()]? The errors you are getting are to be expected but I do not understand what you want to achieve.