numpy requires tuples for indexing where Numeric allowed them?
I'm fighting conversion from Numeric to numpy. One change that doesn't seem documented is that I used to be able to select items using lists and now it seems that I have to convert them to tuples. Is that correct and is there a function buried in there that will accept a list for indices? Any reason that item() can't take a list? The weird thing is that it doesn't blow up right away when a list is passed in an array ref but rather returns something I don't expect. I work with lists rather than the implicit tuples of a function call because then I can work with arbitrary dimensions. In the meantime, I guess I can just convert the list to an otherwise unnecessary tuple. Jim
Hi, Jim, Just wondering why you would use item() rather than index in brackets, i.e. a[i] ? The latter works well in numpy. But maybe I'm missing something. -- Lou Pecora --- Jim Kleckner <jek-cygwin2@kleckner.net> wrote:
I'm fighting conversion from Numeric to numpy.
One change that doesn't seem documented is that I used to be able to select items using lists and now it seems that I have to convert them to tuples. Is that correct and is there a function buried in there that will accept a list for indices?
Any reason that item() can't take a list?
The weird thing is that it doesn't blow up right away when a list is passed in an array ref but rather returns something I don't expect.
I work with lists rather than the implicit tuples of a function call because then I can work with arbitrary dimensions.
In the meantime, I guess I can just convert the list to an otherwise unnecessary tuple.
Jim
-- Lou Pecora, my views are my own. --------------- Great spirits have always encountered violent opposition from mediocre minds. -Albert Einstein ____________________________________________________________________________________ Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's on, when. http://tv.yahoo.com/collections/222
Jim Kleckner wrote:
I'm fighting conversion from Numeric to numpy.
One change that doesn't seem documented is that I used to be able to select items using lists and now it seems that I have to convert them to tuples. Is that correct and is there a function buried in there that will accept a list for indices?
The problem is that with the introduction of arbitrary indexing (indirect indexing), lists are treated as sequences of indices instead of index numbers. There is a bit of logic inserted for backward compatibility, but it isn't perfect. What is the code that you are having trouble with?
Any reason that item() can't take a list?
Not that I can think of. It could probably be updated to take a list.
The weird thing is that it doesn't blow up right away when a list is passed in an array ref but rather returns something I don't expect.
Right, this is the indirect referencing feature that NumPy now supports. -Travis
participants (3)
-
Jim Kleckner
-
Lou Pecora
-
Travis Oliphant