【发布时间】:2018-08-07 19:49:15
【问题描述】:
我有一个像
这样的 numpy 数组result = np.array([[[289, 354, 331],
[291, 206, 66],
[242, 70, 256]],
[[210, 389, 342],
[273, 454, 218],
[255, 87, 256]],
[[127, 342, 173],
[450, 395, 147],
[223, 228, 401]]])
如果元素大于 255,我会尝试屏蔽数组。即我假设它的范围为 0-1024,然后将我的值除以 4
result = np.putmask(result, result > 255, result/4)
注意:结果是之前的 3D 数组。我得到了这个错误
TypeError: Cannot cast array data from dtype('float64') to dtype('int32') according to the rule 'safe'
我做错了什么? 提前致谢
【问题讨论】: