admin管理员组文章数量:1635848
参考:http://stackoverflow/questions/13572448/change-values-in-a-numpy-array
问题:img为numpy.ndarray,在使用img[img<0]=0 语句时,报错ValueError:assignment destination is read-only
(同一代码在win、ubuntu下没问题,而在centos7下报的错)
解决方案:修改ndarray的属性:
img.flags.writeable = True
补充:查看ndarray的属性
import numpy as np
help(np.ndarray.flags)
flags属性是关于数组内存布局的信息。其中,flags属性可以以字典形式修改,比如:
a.flags['WRITEABLE'] = True
也可以使用小写字母属性名:
a.flags.writeable = True
而缩写词('C' / 'F' 等)仅适用于字典形式
仅有属性UPDATEIFCOPY,WRITEABLE以及ALIGNED属性可以被使用者修改,有3种修改方式:
1.直接赋值:
a.flags.writeable = True
2.字典输入:
a.flags['WRITEABLE'] = True
3.使用函数ndarray.setflags:
help(np.ndarray.setflags)
本文标签: ndarraynumpyPythonValueErrorread
版权声明:本文标题:Python Numpy.ndarray ValueError:assignment destination is read-only 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1729215260a1190354.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论