[Numpy-discussion] fromiter + dtype='S' -> Python crash

Alan G Isaac aisaac@american....
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.)

Alan Isaac

>>> import numpy as N
>>> x = [1,2,3]
>>> fmt="%03d"
>>> 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')
Python crashes.

More information about the Numpy-discussion mailing list