[Numpy-discussion] String manipulation

Stéfan van der Walt stefan at sun.ac.za
Wed Jul 22 03:49:48 EDT 2009


2009/7/21 Christopher Barker <Chris.Barker at noaa.gov>:
> In [35]: line
> Out[35]: '-1.000000E+00-1.000000E+00-1.000000E+00-1.000000E+00
> 1.250000E+00 1.250000E+00'
>
> In [36]: a = np.array(line)
>
> In [37]: a
> Out[37]:
> array('-1.000000E+00-1.000000E+00-1.000000E+00-1.000000E+00 1.250000E+00
> 1.250000E+00',
>       dtype='|S78')
>
> but now when I try to split it up:
>
> In [38]: a = a.view(dtype='S13')
>
> I get:
>
> ValueError: new type not compatible with array.

You cannot use view on an array scalar, so you'll have to convert to
an array first:

x = x.reshape((1,))
x.view('S1')

Regards
Stéfan



More information about the NumPy-Discussion mailing list