[Numpy-discussion] Transforming an array of numbers to an array of formatted strings

Alexander Michael lxander.m@gmail....
Thu Mar 13 08:27:45 CDT 2008

Is there a better way than looping to perform the following transformation?

>>> import numpy
>>> int_data = numpy.arange(1,11, dtype=int) # just an example
>>> str_data = int_data.astype('S4')
>>> for i in xrange(len(int_data)):
...     str_data[i] = 'S%03d' % int_data[i]

>>> print str_data
['S001' 'S002' 'S003' 'S004' 'S005' 'S006' 'S007' 'S008' 'S009' 'S010']

That is, I want to format an array of numbers as strings.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080313/7c0fa136/attachment.html 

More information about the Numpy-discussion mailing list