尝试按照示例使用 PIL 创建随机图像:
import numpy
from PIL import image
a = numpy.random.rand(48,84)
img = Image.fromarray(a.astype('uint8')).convert('1')
print(len(img.tobytes()))
Run Code Online (Sandbox Code Playgroud)
这个特定的代码将输出 528。我们翻转 numpy 数组的数字:
a = numpy.random.rand(84,48)
Run Code Online (Sandbox Code Playgroud)
我们得到的输出是 504。这是为什么呢?
我期望字节数相同,因为 numpy 数组的大小相同。