reshape
为此工作
a = np.arange(3) # a.shape = (3,)b = a.reshape((3,1)) # b.shape = (3,1)b2 = a.reshape((-1,1)) # b2.shape = (3,1)c = b.reshape((3,)) # c.shape = (3,)c2 = b.reshape((-1,)) # c2.shape = (3,)
还请注意,
reshape除非需要复制新形状(在这里不需要这样做),否则它不会复制数据:
a.__array_interface__['data'] # (22356720, False)b.__array_interface__['data'] # (22356720, False)c.__array_interface__['data'] # (22356720, False)



