<Numpy-discussion(a)lists.sourceforge.net>Hi,
I am trying to convert an int or float ndarray into a string ndarray. Using
astype this is possible, but only if you explicity set the number of
characters (see eg below). It would be nice if just setting type='S' (or
N.str_) would automatically make an a character array of sufficient size to
hold the string representation. Is there a way to do this?
thanks,
michael
import numpy as N
N.version.version
'0.9.6'
N.arange(20).astype(N.str_)
array([, , , , , , , , , , , , , , , , , , , ],
dtype='|S0')
N.arange(20).astype('S')
array([, , , , , , , , , , , , , , , , , , , ],
dtype='|S0')
N.arange(20).astype('S1')
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
dtype='|S1')
N.arange(20).astype('S2')
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19],
dtype='|S2')