String comparison in Numpy
Posted
by Morgoth
on Stack Overflow
See other posts from Stack Overflow
or by Morgoth
Published on 2010-03-23T15:50:20Z
Indexed on
2010/03/23
15:53 UTC
Read the original article
Hit count: 462
In the following example
In [8]: import numpy as np
In [9]: strings = np.array(['hello ', 'world '], dtype='|S10')
In [10]: strings == 'hello'
Out[10]: array([False, False], dtype=bool)
The comparison fails because of the whitespace. Is there a Numpy built-in function that does the equivalent of
In [12]: np.array([x.strip()=='hello' for x in strings])
Out[12]: array([ True, False], dtype=bool)
which does give the correct result?
© Stack Overflow or respective owner