gpt4 book ai didi

arrays - PIL 类型错误 : Cannot handle this data type: (1, 1, 1), |u1

转载 作者:行者123 更新时间:2023-12-04 12:16:17 27 4
gpt4 key购买 nike

我有一个 numpy.ndarray形状(1,28,28)和值是 [0,1] 范围内的浮点数。我的最终目标是将数组保存为 png 图像。
即使在转置数组并将其乘以 255 以获得 uint 值之后,它仍然会抛出错误 *** TypeError: Cannot handle this data type: (1, 1, 1), |u1 .
我正在使用以下代码:

im = Image.fromarray((img.transpose(1,2,0) * 255).astype(np.uint8))
任何帮助将不胜感激。
附言我已经在处理建议 here .

最佳答案

如果您的图像是灰度图像,则需要向 PIL 传递一个二维数组,即形状必须是 h,w不是 h,w,1 .

im = Image.fromarray((img[0] * 255).astype(np.uint8))

关于arrays - PIL 类型错误 : Cannot handle this data type: (1, 1, 1), |u1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63367136/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com