How to work "if np.array([False]):"
<p>The output of the following code is <strong>NOTHING</strong>.</p>

<pre><code>if np.array([False]):
  print("hello")
</code></pre>

<p>Although I tried to search for it, I don't know how it works. Can Python overload <code>if</code>? </p>

<p>The following is a case of a pure array.</p>

<pre><code>if [False]:
  print("hello")
</code></pre>

<p>The output is <code>hello</code></p>

<p>Would you tell me how to code np.array?</p>

<p>One thing i noticed is <code>if np.array([False])</code> or <code>bool(np.array([False])</code> returns the bool of the only item in the array. And you are not supposed to have more than one item in numpy array if you are doing <code>if</code> or <code>bool</code>. </p>

<p>If there are more than one elements, have to use <code>a.any()</code> or <code>a.all()</code></p>

<pre><code>&gt;&gt;&gt; if np.array([False, False]):
...   print 's'
... 
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
&gt;&gt;&gt; bool(np.array([False, False]))
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; bool(np.array([False, 232]))
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; bool(np.array([False, 232]).any())
True
&gt;&gt;&gt; 
</code></pre>

python numpy