Pseudo-indices -- PEP material?
Magnus Lie Hetland
mlh at furu.idi.ntnu.no
Thu Jun 12 19:31:09 CEST 2003
I've found I kind of like the capability of numarray to use sequences
as keys to arrays, e.g:
>>> a
array([1, 2, 3, 4])
>>> a[[1, 3]]
array([2, 4])
>>> a[[0, 3]] = [5, 6]
>>> a
array([5, 2, 3, 6])
Now we can do similar things with the new slice abilities of 2.3
lists:
>>> a
[1, 2, 3, 4]
>>> a[1::2]
[2, 4]
>>> a[::3] = [5, 6]
[5, 2, 3, 6]
This is, however, still a bit restricted. We can only use arithmetic
sequences as (pseudo-)indices. I think it would be nice to be able to
use arbitrary sequences. It is mainly a syntactic nicety, although
moving the necessary loop to C might speed things up a bit too.
Of course numarray can use multidimensional arrays as
(pseudo-)indices; that wouldn't be applicable here, since lists are
only one-dimensional.
Does this seem like nonsense? Does anyone else like it? 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
Solaris at the moment... :)
--
Magnus Lie Hetland "In this house we obey the laws of
http://hetland.org thermodynamics!" Homer Simpson
More information about the Python-list
mailing list