[NumPy-Tickets] [NumPy] #402: newaxis incompatible with array indexing
NumPy Trac
numpy-tickets@scipy....
Wed Mar 23 13:34:52 CDT 2011
#402: newaxis incompatible with array indexing
---------------------------+------------------------------------------------
Reporter: NeilenMarais | Owner: somebody
Type: enhancement | Status: closed
Priority: normal | Milestone: Unscheduled
Component: numpy.core | Version:
Resolution: wontfix | Keywords:
---------------------------+------------------------------------------------
Comment(by mwiebe):
Perhaps a better way to phrase what I mean is to remove the current
interface to fancy indexing. It requires extra thought, and easily trips
people up, as evidenced by a number of mailing list questions.
{{{
In [25]: a = np.arange(12).reshape(4,3)
In [26]: a[[0,2,3]]
Out[26]:
array([[ 0, 1, 2],
[ 6, 7, 8],
[ 9, 10, 11]])
# So lists in index 0 select rows
In [27]: a[:,[2,1,2]]
Out[27]:
array([[ 2, 1, 2],
[ 5, 4, 5],
[ 8, 7, 8],
[11, 10, 11]])
# Cool, lists in index 1 select columns, let's put that together...
In [28]: a[[0,2,3],[2,1,2]]
Out[28]: array([ 2, 7, 11])
# What happened? Totally unexpected, especially since the following works:
In [31]: a[0:2,1:3]
Out[31]:
array([[1, 2],
[4, 5]])
# So when someone thinks "now let's replace the slice with a list because
# I need rows/columns that aren't in a linear sequence," the behavior will
# be confusing.
}}}
I would suggest the take function should be generalized to do multi-
indexing as a replacement for the current fancy indexing.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/402#comment:10>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list