Slicing wrapped numpy arrays

Martin Manns mmanns at
Sun Jan 13 22:31:15 CET 2008


I have created a class that wraps a numpy array of custom objects. I
would like to be able to slice respective objects (without copying the
array if possible).

I have browsed the doc and found some hints at __getitem__. However, I
still do not grasp how to do it.  How do I implement __getitem__

from numpy import *

class Cell(object):

class Map(object):
    def __init__(self, dimensions):

    def generate_map(self, dimensions):
        map_range = xrange(reduce(lambda x,y: x*y, dimensions)) = array([Cell() for i in map_range]) =

mymap = Map((100, 100, 100))
mymap[10:20,15:20,:] # This line should work afterwards

Thanks in advance


More information about the Python-list mailing list