I am trying to write my own matrix class in python, just for testing purposes. In reality, this matrix class is in c++ and I am using SWIG to interface between the two. However, for this question, it might be simpler to consider a pure python implementation of this matrix class.
I want to be able to call this matrix class and use two-indexed slicing. For example, after we create 4x4 matrix of ones,
>>> A = Matrix(4,4,1)
I want to be able to get the sub 2x2 matrix:
>>>> A[1:2,1:2]
I've heard of the __getslice__
method, but this seems like it only allows single slicing, e.g. A[1:2]
. So how can perform a two-index slicing so I can call A[i:j,l:k]
?
Thanks!