*tuple

*tuple,第1张

*tuple * unpacked a tuple, 对tuple 解包
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) # * 解包

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5700728.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存