Is there are a way to use Numpy's multidimensional array slicing without using the [slice, slice] syntax?
I need to be able to use it from normal function calls, but I haven't found a way to use the slice object to do it.
I cannot use the syntax [(slice,slice)]
for my program because []
is special syntax outside of regular function calls.
The language I am using is Hy, a Lisp for Python, and it does not support this syntax. More importantly, it shouldn't support this syntax. Numpy, however, doesn't seem to support multidimensional slicing without using the []
syntax.
What's tripping me up is that the mix of C and Python in the Numpy source makes it difficult to discern how the [slice,slice]
is implemented.
It may not even be possible to circumvent this syntax.
EDIT:
The answer provided below by @Joe Kington allows one to slice Numpy matrices like so:
x = np.array([list(range(5)) for x in list(range(5))])
x.getitem(slice(1,4))
array([[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4]])
x.getitem(tuple([slice(1,4),slice(1,4)]))
array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])
[bla, blah]
is just[(blah, blah)]
I bet there are many questions about this... – seberg Mar 20 at 19:25arr.__getitem__(tuple_of_slice_objects)
, and__setitem__
for assignment. (Incidentally, your edits helped make the question much more clear. I think it's a good question.) – Joe Kington Mar 21 at 17:44