<p dir="auto">NumPy can create boolean arrays out of strings, but cannot convert string arrays to bool_. I think we should follow Python here and assign truth values to strings.</p>
<h3 dir="auto">Reproducing code example:</h3>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; np.array('N', dtype='?')
array(True)
&gt;&gt;&gt; np.array('N').astype('?')
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
ValueError: invalid literal for int() with base 10: 'N'"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-s">'N'</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'?'</span>)
<span class="pl-en">array</span>(<span class="pl-c1">True</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-s">'N'</span>).<span class="pl-en">astype</span>(<span class="pl-s">'?'</span>)
<span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>):
  <span class="pl-v">File</span> <span class="pl-s">"&lt;stdin&gt;"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1</span>, <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
<span class="pl-v">ValueError</span>: <span class="pl-s1">invalid</span> <span class="pl-s1">literal</span> <span class="pl-k">for</span> <span class="pl-en">int</span>() <span class="pl-s1">with</span> <span class="pl-s1">base</span> <span class="pl-c1">10</span>: <span class="pl-s">'N'</span></pre></div>

<h3 dir="auto">Error message:</h3>


<h3 dir="auto">Numpy/Python version information:</h3>
<p dir="auto">The following table shows the extents of the problem</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="x : str
sc = np.str_(x)
arr = np.array(x, np.str_)"><pre class="notranslate"><span class="pl-s1">x</span> : <span class="pl-s1">str</span>
<span class="pl-s1">sc</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">str_</span>(<span class="pl-s1">x</span>)
<span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-s1">x</span>, <span class="pl-s1">np</span>.<span class="pl-s1">str_</span>)</pre></div>
<table role="table">
<thead>
<tr>
<th><code class="notranslate">x</code></th>
<th><code class="notranslate">bool(x)</code></th>
<th><code class="notranslate">bool(sc)</code></th>
<th><code class="notranslate">bool(arr[()])</code></th>
<th><code class="notranslate">bool(arr)</code></th>
<th><code class="notranslate">sc.astype(bool)</code></th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="notranslate">''</code></td>
<td><code class="notranslate">False</code></td>
<td><code class="notranslate">False</code></td>
<td><code class="notranslate">False</code></td>
<td><code class="notranslate">False</code></td>
<td><code class="notranslate">ValueError</code></td>
</tr>
<tr>
<td><code class="notranslate">'\0'</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">False</code></td>
<td><code class="notranslate">False</code></td>
<td><code class="notranslate">ValueError</code></td>
</tr>
<tr>
<td><code class="notranslate">' '</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">False</code></td>
<td><code class="notranslate">ValueError</code></td>
</tr>
<tr>
<td><code class="notranslate">' \0'</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">False</code></td>
<td><code class="notranslate">ValueError</code></td>
</tr>
<tr>
<td><code class="notranslate">'0'</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">False</code></td>
</tr>
<tr>
<td><code class="notranslate">'1'</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
</tr>
<tr>
<td><code class="notranslate">'\0 '</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">ValueError</code></td>
</tr>
<tr>
<td><code class="notranslate">' \0 '</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">True</code></td>
<td><code class="notranslate">ValueError</code></td>
</tr>
</tbody>
</table>
 <details>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="def call_or_exc(f):
    try:
        return f()
    except Exception as e:
        return e

def truthiness(x):
    x_arr = np.array(x)
    x_sc = np.unicode_(x)
    x_sc2 = x_arr[()]
    return bool(x), bool(x_sc), bool(x_sc2), bool(x_arr), call_or_exc(lambda: x_sc.astype(bool))

def fmt(x):
    if isinstance(x, str): return repr(x).replace(r'\x00', r'\0')
    if isinstance(x, Exception): return type(x).__name__
    return repr(x)

print(' | '.join(&quot;`{}`&quot;.format(x) for x in ['x', 'bool(x)', 'bool(sc)', 'bool(arr[()])', 'bool(arr)', 'sc.astype(bool)']))
print(' | '.join(['--'] * 6))
for val in ['', '\0', ' ', ' \0', '0', '1', '\0 ', ' \0 ']:
   print(' | '.join(&quot;`{}`&quot;.format(fmt(x)) for x in (val,)+truthiness(val)))"><pre class="notranslate"><span class="pl-k">def</span> <span class="pl-en">call_or_exc</span>(<span class="pl-s1">f</span>):
    <span class="pl-k">try</span>:
        <span class="pl-k">return</span> <span class="pl-en">f</span>()
    <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">e</span>:
        <span class="pl-k">return</span> <span class="pl-s1">e</span>

<span class="pl-k">def</span> <span class="pl-en">truthiness</span>(<span class="pl-s1">x</span>):
    <span class="pl-s1">x_arr</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-s1">x</span>)
    <span class="pl-s1">x_sc</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">unicode_</span>(<span class="pl-s1">x</span>)
    <span class="pl-s1">x_sc2</span> <span class="pl-c1">=</span> <span class="pl-s1">x_arr</span>[()]
    <span class="pl-k">return</span> <span class="pl-en">bool</span>(<span class="pl-s1">x</span>), <span class="pl-en">bool</span>(<span class="pl-s1">x_sc</span>), <span class="pl-en">bool</span>(<span class="pl-s1">x_sc2</span>), <span class="pl-en">bool</span>(<span class="pl-s1">x_arr</span>), <span class="pl-en">call_or_exc</span>(<span class="pl-k">lambda</span>: <span class="pl-s1">x_sc</span>.<span class="pl-en">astype</span>(<span class="pl-s1">bool</span>))

<span class="pl-k">def</span> <span class="pl-en">fmt</span>(<span class="pl-s1">x</span>):
    <span class="pl-k">if</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">x</span>, <span class="pl-s1">str</span>): <span class="pl-k">return</span> <span class="pl-en">repr</span>(<span class="pl-s1">x</span>).<span class="pl-en">replace</span>(<span class="pl-s">r'\x00'</span>, <span class="pl-s">r'\0'</span>)
    <span class="pl-k">if</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">x</span>, <span class="pl-v">Exception</span>): <span class="pl-k">return</span> <span class="pl-en">type</span>(<span class="pl-s1">x</span>).<span class="pl-s1">__name__</span>
    <span class="pl-k">return</span> <span class="pl-en">repr</span>(<span class="pl-s1">x</span>)

<span class="pl-en">print</span>(<span class="pl-s">' | '</span>.<span class="pl-en">join</span>(<span class="pl-s">"`{}`"</span>.<span class="pl-en">format</span>(<span class="pl-s1">x</span>) <span class="pl-k">for</span> <span class="pl-s1">x</span> <span class="pl-c1">in</span> [<span class="pl-s">'x'</span>, <span class="pl-s">'bool(x)'</span>, <span class="pl-s">'bool(sc)'</span>, <span class="pl-s">'bool(arr[()])'</span>, <span class="pl-s">'bool(arr)'</span>, <span class="pl-s">'sc.astype(bool)'</span>]))
<span class="pl-en">print</span>(<span class="pl-s">' | '</span>.<span class="pl-en">join</span>([<span class="pl-s">'--'</span>] <span class="pl-c1">*</span> <span class="pl-c1">6</span>))
<span class="pl-k">for</span> <span class="pl-s1">val</span> <span class="pl-c1">in</span> [<span class="pl-s">''</span>, <span class="pl-s">'\0'</span>, <span class="pl-s">' '</span>, <span class="pl-s">' \0'</span>, <span class="pl-s">'0'</span>, <span class="pl-s">'1'</span>, <span class="pl-s">'\0 '</span>, <span class="pl-s">' \0 '</span>]:
   <span class="pl-en">print</span>(<span class="pl-s">' | '</span>.<span class="pl-en">join</span>(<span class="pl-s">"`{}`"</span>.<span class="pl-en">format</span>(<span class="pl-en">fmt</span>(<span class="pl-s1">x</span>)) <span class="pl-k">for</span> <span class="pl-s1">x</span> <span class="pl-c1">in</span> (<span class="pl-s1">val</span>,)<span class="pl-c1">+</span><span class="pl-en">truthiness</span>(<span class="pl-s1">val</span>)))</pre></div>
<summary>Generated with...</summary>
</details>
<p dir="auto">The differences come down to:</p>
<ul dir="auto">
<li><code class="notranslate">bool(arr[()])</code> - indexing string arrays causes trailing nulls to be truncated. This is unavoidable.</li>
<li><code class="notranslate">bool(arr)</code> - has special handling to treat spaces as falsy. This seems unpythonic, since that's not how <code class="notranslate">str.__bool__</code> behaves - are we stuck with it</li>
<li><code class="notranslate">arr.astype(bool)</code> - treated as <code class="notranslate">arr.astype(int).astype(bool)</code>, which seems bizarre</li>
</ul>