首页 > 解决方案 > AttributeError: 'list' 对象没有属性 'shape' 问题

问题描述

我正在尝试获取数组(文件)中的值,并且我想将它们保存在一个目录中,所以我正在使用 plt.imsave(os.path.join())并且我遇到了一个问题:

代码 : for i in tab: plt.imsave(os.path.join(target_directory,str(i)), tab)

我收到这个错误AttributeError: 'list' object has no attribute 'shape'

有人有想法吗?谢谢

标签: pythonmatplotlibshapes

解决方案


tab可能不是您的图像,因为您正在对其进行迭代。

事实上,tab很可能是一个列表,而 Matplotlibimsave期望它是一个 numpy 数组(它有一个shape属性)。

我的猜测是你不打算传递tabimsave其他东西。


推荐阅读