Pseudo-indices -- PEP material?

Raymond Hettinger vze4rx4y at
Fri Jun 13 08:49:03 CEST 2003

[Magnus Lie Hetland]
> I've found I kind of like the capability of numarray to use sequences
> as keys to arrays, e.g:

I like it too.
Rather, I like it in numarray and am -1 for having in the Python core.

It represents a different style of thinking that is best
left the numeric packages.

1) The pythonic way is less about reasoning with indicies and more
about applying the conditions or logic that generate an array of

Experience with APL and Matlab show code using index arrays
is semi-easy to write, a little bit harder to read for your own code,
and super hard to read in someone else's code.

Look at the code inside meshgrid() or some of Matlab's other array
index manipulators.  A little aspirin is a must when dealing with this code.

> >>> a
> array([1, 2, 3, 4])
> >>> a[[1, 3]]
> array([2, 4])
> >>> a[[0, 3]] = [5, 6]
> >>> a
> array([5, 2, 3, 6])

2) Equivalent functionality is already available with very few keystrokes:

>>> a = [1,2,3,4]
>>> map(a.__getitem__, [1,3])
[2, 4]
>>> map(a.__setitem__, [0, 3], [5, 6])
[None, None]
>>> a
[5, 2, 3, 6]

> Does this seem like nonsense? Does anyone else like it?

No me.

> Is it worth
> consideration as a PEP?
> Maybe one should just use numarray for this
> sort of thing in the first place?


> (The reason I started thinking about
> this is that I can't get any version of numarray to work with Py3b1 in

Wow, Python 3.0  made it to beta before 2.3 got out.  Go figure ;-)

Raymond Hettinger

More information about the Python-list mailing list