A more compact __repr__ for my numpy array?
问题 When I show an array, the default __repr__() method for ndarray objects is too big for what I would like to do: a = np.eye(32) b = {'hello':42, 'array':a} b produces: {'array': array([[ 1., 0., 0., ..., 0., 0., 0.], [ 0., 1., 0., ..., 0., 0., 0.], [ 0., 0., 1., ..., 0., 0., 0.], ..., [ 0., 0., 0., ..., 1., 0., 0.], [ 0., 0., 0., ..., 0., 1., 0.], [ 0., 0., 0., ..., 0., 0., 1.]]), 'hello': 42} I tried an ugly solution, reassigning __repr__ : def wow(): return "wow!" a.__repr__ = wow which