[Numpy-discussion] Advanced indexing: "fancy" vs. orthogonal

josef.pktd at gmail.com josef.pktd at gmail.com
Thu Apr 2 21:35:55 EDT 2015


On Thu, Apr 2, 2015 at 9:09 PM,  <josef.pktd at gmail.com> wrote:
> On Thu, Apr 2, 2015 at 8:02 PM, Eric Firing <efiring at hawaii.edu> wrote:
>> On 2015/04/02 1:14 PM, Hanno Klemm wrote:
>>> Well, I have written quite a bit of code that relies on fancy
>>> indexing, and I think the question, if the behaviour of the []
>>> operator should be changed has sailed with numpy now at version 1.9.
>>> Given the amount packages that rely on numpy, changing this
>>> fundamental behaviour would not be a clever move.
>>
>> Are you *positive* that there is no clever way to make a transition?
>> It's not worth any further thought?
>
> I guess it would be similar to python 3 string versus bytes, but
> without the overwhelming benefits.
>
> I don't think I would be in favor of deprecating fancy indexing even
> if it were possible. In general, my impression is that if there is a
> trade-off in numpy between powerful machinery versus easy to learn and
> teach, then the design philosophy when in favor of power.
>
> I think numpy indexing is not too difficult and follows a consistent
> pattern, and I completely avoid mixing slices and index arrays with
> ndim > 2.
>
> I think it should be DOA, except as a discussion topic for numpy 3000.
>
> just my opinion


is this fancy?

>>> vals
array([6, 5, 4, 1, 2, 3])
>>> a+b
array([[3, 2, 1, 0],
       [4, 3, 2, 1],
       [5, 4, 3, 2]])
>>> vals[a+b]
array([[1, 4, 5, 6],
       [2, 1, 4, 5],
       [3, 2, 1, 4]])

https://github.com/scipy/scipy/blob/v0.14.0/scipy/linalg/special_matrices.py#L178

(I thought about this because I was looking at accessing off-diagonal
elements, m2[np.arange(4), np.arange(4) + 1] )


How would you find all the code that would not be correct anymore with
a changed definition of indexing and slicing, if there is insufficient
test coverage and it doesn't raise an exception?
If we find it, who fixes all the legacy code? (I don't think it will
be minor unless there is a new method `fix_[...]`  (fancy ix)

Josef

>
> Josef
>
>>
>>>
>>> If people want to implement orthogonal indexing with another method,
>>> by all means I might use it at some point in the future. However,
>>> adding even more complexity to the behaviour of the bracket slicing
>>> is probably not a good idea.
>>
>> I'm not advocating adding even more complexity, I'm trying to think
>> about ways to make it *less* complex from the typical user's standpoint.
>>
>> Eric
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion



More information about the NumPy-Discussion mailing list