[Numpy-discussion] structured array with submember assign

Fabian Dill Fabian.Dill at web.de
Mon Dec 26 16:51:12 EST 2011

tiles = numpy.zeros((header["width"], header["height"]), dtype =  [("0","<u2"),("1","|u1"),("2","|u1")])
tiles["0"][0,0] = 1

that does work now. however it's much slower in assigning and I cannot use integers for the first index.

As it's now I might as well do:
tiles = [numpy.zeros((header["width"], header["height"]), dtype = numpy.uint16),
            numpy.zeros((header["width"], header["height"]), dtype = numpy.uint8),
            numpy.zeros((header["width"], header["height"]), dtype = numpy.uint8)]
Which allows tiles[0][0,0] = 1

The main problem is, that this change is in place within a larger project. I would like the new array to be usable just as the old one, with little to no change in code.

Is there a way to achieve that? Or failing that, which is the most efficient way, when I have lots of single member handling, so the rewrite is worth it.
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192

More information about the NumPy-Discussion mailing list