import numpy as np a = np.zeros((2,3,3)) print(a) dim = a.shape[:2] print(dim) print(*dim)
输出:
[[[0. 0. 0.] [0. 0. 0.] [0. 0. 0.]] [[0. 0. 0.] [0. 0. 0.] [0. 0. 0.]]] (2, 3) 2 3
或者这样用
class CIFAR_Image: def __init__(self, image, label): # Dimensions of image for reconstruction - not really necessary # for this dataset, but some datasets may include images of # varying sizes self.channels = image.shape[2] self.size = image.shape[:2] self.image = image.tobytes() self.label = label def get_image(self): """ Returns the image as a numpy array. """ image = np.frombuffer(self.image, dtype=np.uint8) return image.reshape(*self.size, self.channels) # * 解包
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)