我写了一个循环,里面有个if判断,根据判断结果给矩阵赋值data_old[i,j] = 266
,结果每次赋值都矩阵那个位置的值不是266,而是10,这是为什么?
估计你定义的数据类型的原因,如果是 uint8,则会溢出:
>>> import numpy as np
>>> a = np.array([1, 2, 3], dtype = np.uint8)
>>> a
array([1, 2, 3], dtype=uint8)
>>> a[0]=266
>>> a
array([10, 2, 3], dtype=uint8)
>>> a.itemsize
1
uint8的取值范围是0~255, 266-256=10.
itemsize属性会返回类型字节数。