Skip to content

Instantly share code, notes, and snippets.

@dhermes
Created October 10, 2014 17:56
Show Gist options
  • Save dhermes/a24efeed7b2752454340 to your computer and use it in GitHub Desktop.
Save dhermes/a24efeed7b2752454340 to your computer and use it in GitHub Desktop.
NumPy array truthiness
>>> import numpy as np
>>> bool(np.array([]))
False
>>> bool(np.array([1]))
True
>>> bool(np.array([0]))
False
>>> bool(np.array([0,0]))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment