Skip to content

Converting array of strings to bool array #9479

@jakirkham

Description

@jakirkham

It seems that casting an array of strings to a bool array fails. Would have expected that this simply applies NumPy's non-zero criteria on the array. An example of this is shown below with details about the environment.

Code snippet:

Details
In [1]: import numpy as np

In [2]: a = np.array(list("Hello world"))

In [3]: a.astype(bool)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-84491bd66a77> in <module>()
----> 1 a.astype(bool)

ValueError: invalid literal for int() with base 10: 'H'

Environment:

Details
name: np2
channels:
- conda-forge
- defaults
dependencies:
- appnope=0.1.0=py27_0
- backports.shutil_get_terminal_size=1.0.0=py27_1
- blas=1.1=openblas
- ca-certificates=2017.4.17=0
- certifi=2017.4.17=py27_0
- decorator=4.1.1=py27_0
- enum34=1.1.6=py27_1
- ipython=5.4.1=py27_0
- ipython_genutils=0.2.0=py27_0
- libgfortran=3.0.0=0
- ncurses=5.9=10
- numpy=1.13.1=py27_blas_openblas_200
- openblas=0.2.19=2
- openssl=1.0.2l=0
- pathlib2=2.3.0=py27_0
- pexpect=4.2.1=py27_0
- pickleshare=0.7.3=py27_0
- pip=9.0.1=py27_0
- prompt_toolkit=1.0.14=py27_0
- ptyprocess=0.5.2=py27_0
- pygments=2.2.0=py27_0
- python=2.7.13=1
- readline=6.2=0
- scandir=1.5=py27_1
- setuptools=36.2.2=py27_0
- simplegeneric=0.8.1=py27_0
- six=1.10.0=py27_1
- sqlite=3.13.0=1
- tk=8.5.19=1
- traitlets=4.3.2=py27_0
- wcwidth=0.1.7=py27_0
- wheel=0.29.0=py27_0
- zlib=1.2.11=0
- pip:
  - backports.shutil-get-terminal-size==1.0.0
  - ipython-genutils==0.2.0
  - prompt-toolkit==1.0.14

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions