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><code>if [False]:</code> will always be <code>True</code> because <code>[Flase]</code> is a list with one item (i.e., non-empty), so the <code>if</code> block will be entered and you will see the output of your <code>print</code> call. </p>

<p><code>np.array([False])</code></p>

<p>returns a <code>numpy.ndarray</code>, which in this case evaluates to <code>False</code>, so the <code>if</code> block will never be entered and you will not see any output. </p>

python numpy