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

2008-03-13 Thread Alexander Michael
On Thu, Mar 13, 2008 at 9:49 AM, Alan G Isaac <[EMAIL PROTECTED]> wrote: > And for 1d array ``x`` you can always do:: > >strdata = list( fmt%xi for xi in x) > > Nice because the counter name does not "bleed" into your program. On Thu, Mar 13, 2008 at 3:07 PM, David Huard <[EMAIL PROTECTED]> wr

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

2008-03-13 Thread Alan G Isaac
> 2008/3/13, Alan G Isaac <[EMAIL PROTECTED]>: >> strdata = list( fmt%xi for xi in x) >> Nice because the counter name does not "bleed" into your program. On Thu, 13 Mar 2008, David Huard apparently wrote: > ['S%03d'%i for i in int_data] The difference is that the counter "bleeds" from th

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

2008-03-13 Thread David Huard
['S%03d'%i for i in int_data] David 2008/3/13, Alan G Isaac <[EMAIL PROTECTED]>: > > On Thu, 13 Mar 2008, Alexander Michael apparently wrote: > > I want to format an array of numbers as strings. > > > To what end? > Note that tofile has a format option. > And for 1d array ``x`` you can always do

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

2008-03-13 Thread Alan G Isaac
On Thu, 13 Mar 2008, Alexander Michael apparently wrote: > I want to format an array of numbers as strings. To what end? Note that tofile has a format option. And for 1d array ``x`` you can always do:: strdata = list( fmt%xi for xi in x) Nice because the counter name does not "bleed" into y

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

2008-03-13 Thread Alexander Michael
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 ['S00