[Numpy-discussion] fromiter + dtype='S' -> Python crash
Alan G Isaac
Thu Mar 13 16:44:54 CDT 2008
On Thu, 13 Mar 2008, Alexander Michael apparently wrote:
> I wasn't sure if there was a magic numpy
> method to do the loop quickly (as the destination array is created
> beforehand) without creating a temporary Python list, but I guess not.
> The generator/list-comprehension is likely better than my prototype.
Looks like I misunderstood your question:
you want an **array** of strings?
In principle you should be able to use ``fromiter``,
I believe, but it does not work. BUG? (Crasher.)
>>> import numpy as N
>>> x = [1,2,3]
>>> N.array([fmt%xi for xi in x],dtype='S')
array(['001', '002', '003'],
>>> N.fromiter([xi for xi in x],dtype='float')
array([ 1., 2., 3.])
>>> N.fromiter([xi for xi in x],dtype='S')
More information about the Numpy-discussion