Re: [Numpy-discussion] How to avoid extra copying when forming an array from an iterator

2011-06-24 Thread Robert Kern
On Fri, Jun 24, 2011 at 14:38, srean wrote: > A valiant exercise in hope: > > Is this possible to do it without a loop or extra copying. What I have is an > iterator that yields a fixed with string on every call to next(). Now I want > to create a numpy array of ints out of the last 4 chars of tha

Re: [Numpy-discussion] How to avoid extra copying when forming an array from an iterator

2011-06-24 Thread srean
A valiant exercise in hope: Is this possible to do it without a loop or extra copying. What I have is an iterator that yields a fixed with string on every call to next(). Now I want to create a numpy array of ints out of the last 4 chars of that string. My plan was to pass the iterator through a

Re: [Numpy-discussion] How to avoid extra copying when forming an array from an iterator

2011-06-24 Thread srean
On Fri, Jun 24, 2011 at 9:12 AM, Robert Kern wrote: > On Fri, Jun 24, 2011 at 04:03, srean wrote: > > To answer my own question, I guess I can keep appending to a > array.array() > > object and get a numpy.array from its buffer if possible. Is that the > > efficient way. > > It's one of the mos

Re: [Numpy-discussion] How to avoid extra copying when forming an array from an iterator

2011-06-24 Thread Robert Kern
On Fri, Jun 24, 2011 at 04:03, srean wrote: > To answer my own question, I guess I can keep appending to a array.array() > object and get a numpy.array from its buffer if possible.  Is that the > efficient way. It's one of the most efficient ways to do it, yes, especially for 1D arrays. -- Robe

Re: [Numpy-discussion] How to avoid extra copying when forming an array from an iterator

2011-06-24 Thread srean
To answer my own question, I guess I can keep appending to a array.array() object and get a numpy.array from its buffer if possible. Is that the efficient way. On Fri, Jun 24, 2011 at 2:35 AM, srean wrote: > Hi, > > I have an iterator that yields a complex object. I want to make an array > out

[Numpy-discussion] How to avoid extra copying when forming an array from an iterator

2011-06-24 Thread srean
Hi, I have a iterator that yields a complex object. I want to make an array out of a numerical attribute that the yielded object possesses and that too very efficiently. My initial plan was to keep writing the numbers to a StringIO object and when done generate the numpy array using StringIO's bu