set to array

Christopher T King squirrel at WPI.EDU
Fri Jul 30 21:01:06 CEST 2004


On Fri, 30 Jul 2004, Alan G Isaac wrote:

> Numeric.array(myset) returns an array with
> one element, which is the set.
> 
> i. Even allowing that sets are not sequence types,
> is this not surprising?

As you imply, Numeric/numarray only understands sequences.  The only way
you can get a sequence (say, a list) from a set is to use list(myset).  
list(myset) works because it interprets myset as an iterable (which it is)
rather than as a sequence (which it isn't).

Numeric can't accept iterables because one cannot know the size of an
iterable in advance, something Numeric requires in order to preallocate
its buffers.  So for now, Numeric.array(list(myset)) is your best bet
(though it is somewhat inefficient).

Perhaps the good people working on numarray could allow array() to accept 
iterables, provided the shape attribute is also provided (so that the 
length is known beforehand)?




More information about the Python-list mailing list