numpy array of objects
You can vectorize the class’s __init__ function: import numpy as np class Site: def __init__(self, a): self.a = a def set_a(self, new_a): self.a = new_a vSite = np.vectorize(Site) init_arry = np.arange(9).reshape((3,3)) lattice = np.empty((3,3), dtype=object) lattice[:,:] = vSite(init_arry) This may look cleaner but has no performance advantage over your looping solution. The list comprehension answers … Read more