I want to convert a __getitem__
method from python to accept arrays from cython. I should allow slicing in the second index in this particular application. For python I could write:
class name:
def __init__(self):
self.numbers = np.random.rand(2,3)
# ...
# ...
def __getitem__(self, tup):
if type(tup) == tuple:
x, y = tup
return self.numbers[x][y]
return self.numbers[tup]
and everything would work great. However, the interpreter doesn't like it when I declare the variable numbers
to be the type cdef public double[:,:] numbers
and try to call the __getitem__
-method with y
being a slice
-object. Whenever that happens it complains TypeError: 'slice' object cannot be interpreted as an integer. My question is then: How would I modify the line return self.bounds[x][y]
such that y
is correctly understood in case it's a slice
instead of an integer?