8000 numpy not working with itertools.chain objects (Trac #1005) · Issue #1603 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

numpy not working with itertools.chain objects (Trac #1005) #1603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thouis opened this issue Oct 19, 2012 · 3 comments
Closed

numpy not working with itertools.chain objects (Trac #1005) #1603

thouis opened this issue Oct 19, 2012 · 3 comments

Comments

@thouis
Copy link
Contributor
thouis commented Oct 19, 2012

Original ticket http://projects.scipy.org/numpy/ticket/1005 on 2009-02-11 by trac user rogerbrent, assigned to unknown.

numpy.array(), numpy.sum(), etc. don't seem to work with itertools.chain objects.

e.g.:

from itertools import chain

iter = chain(xrange(5))

array(iter)

returns array(<itertools.chain object at 0x0172C828>, dtype=object).
list(iter) would work as expected, returning [0, 1, 2, 3, 4].

However if I define my own chain() function then array(iter) works fine.

Python v2.5.4 and numpy v1.2.1

@thouis
Copy link
Contributor Author
thouis commented Oct 19, 2012

trac user rogerbrent wrote on 2009-02-12

Is there a recommended way to use numpy.sum() with a chain iterator that returns numpy arrays? Also, is there a reason why array()/sum() work with normal iterators but not with itertools.chain?

@thouis
Copy link
Contributor Author
thouis commented Oct 19, 2012

@rkern wrote on 2009-02-12

Generally, iterators are not supported as arguments to array(). Use fromiter() instead. There isn't a good way to implement array() to take iterators, too. fromiter() makes some assumptions in order to support this for 1D iterators of scalars, but array() cannot make these assumptions.

@thouis
Copy link
Contributor Author
thouis commented Oct 19, 2012

@rkern wrote on 2009-02-12

You can just use the builtin sum() function. array() does not work with normal iterators, just sequences. xrange(), for example, is a sequence, not an iterator. It has __len__ and __getitem__ methods. I don't know exactly what you've tried that leads you to think that normal iterators work.

If you want to talk about it more, please ask on the mailing list. Trac tickets aren't good for back-and-forth conversations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant
0