[Numpy-discussion] PyArray_FromAny does not accept a generator?

Neal Becker ndbecker2@gmail....
Sun Jan 6 05:20:32 CST 2008

Robert Kern wrote:

> Neal Becker wrote:
>> It seems that PyArray_FromAny does not accept a generator?
>> Seems like this would be useful.
> It's difficult to do all the magical interpretation that PyArray_FromAny()
> does with a iterator of unknown length. In Python, we have fromiter()
> which will consume an iterator to make (only) a rank-1 array and thus
> sidestep a big chunk of the magical interpretation.

I have previously created a wrapper for python around boost::ublas vector.
Basically it does (in pseudocode):

  if (obj is a vector):
    return a copy
  elif (obj has __len__):
    return vector_from_sequence
  elif (obj has __iter__):
    return vector_from_iter

  copy_iter_to_new_temp_container (in this case, we use std::vector with
  return new vector from temp container

More information about the Numpy-discussion mailing list