[MATRIX-SIG] A proposal (LONG) - "reverse of take"
revisited
Andrew P. Mullhaupt
amullhau@ix.netcom.com
Fri, 11 Jul 1997 17:54:39 -0400
At 12:08 PM 7/11/97 -0400, Chase, Chris wrote:
>
>Slices that go outside array bounds are silently projected onto the
>bounds while take() generates an error when the index vector goes
>outside the bounds. If arrays were allowed as indexes should they
>behave like slices or like take()?
>
Actually, _functions_ such as take should not be tied to the behavior
of indices. You can write all sorts of functions to do anything you
want, so the user shouldn't have an expectation of a connection between
index semantics and function semantics except for the _very few_
necessary functions which explicitly involve the shape of the array.
So for consistency they can behave like slices, but I'm a bit surprised
at how you claim slice indices work.
So I tried some examples and I think slice indices are broken. For example:
Python 1.4 (Feb 24 1997) [C]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> a = reshape(range(12), [3, 4])
>>> a[0:3, 0:4]
0 1 2 3
4 5 6 7
8 9 10 11
>>> a[0:4, 0:4]
0 1 2 3
4 5 6 7
8 9 10 11
>>> a[-1:4, 0:4]
8 9 10 11
>>> a[4:0, 0:4]
EmptyArray
>>> a[3:0, 0:4]
EmptyArray
>>> a[3:0:-1, 0:4]
0 0 209 0
8 9 10 11
4 5 6 7
>>> a[3:0:-1, 4:0:-1]
1 0 209 0
0 11 10 9
8 7 6 5
>>>
Whoa! Let's try that again:
Python 1.4 (Feb 24 1997) [C]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> a = reshape(range(12), [3, 4])
>>> a = reshape(range(12), [3, 4])
>>> a[3:0:-1, 4:0:-1]
1936654336 7103790 1328443513 1768843081
0 11 10 9
8 7 6 5
>>> a = reshape(range(12), [3, 4])
>>> a[3:0:-1, 4:0:-1]
0 1545120 41 0
0 11 10 9
8 7 6 5
Broken, Yes?
Later,
Andrew Mullhaupt
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________