set to array

A

Alan G Isaac

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?

ii. What is the best way to produce an array of
the set elements?

Thanks,
Alan Isaac
 
C

Christopher T King

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)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top