我想评估for循环内的表达式。我做:如何使用Python评估for循环中的表达式?
for i in range(0,255):
Q[i+1,1] = (np.floor_divide(i, q) * q + q/2)
但这返回一个错误,说
IndexError: index 1 is out of bounds for axis 1 with size 1".
我想评估for循环内的表达式。我做:如何使用Python评估for循环中的表达式?
for i in range(0,255):
Q[i+1,1] = (np.floor_divide(i, q) * q + q/2)
但这返回一个错误,说
IndexError: index 1 is out of bounds for axis 1 with size 1".
大小256x1但你仍然要与指数0开始所以,你需要Q[i,0]
蟒蛇 (和numpy)使用zero-based indexing,所以第一个位置是0.您应该将您的循环更改为:
for i in range(0,255):
Q[i,0] = (np.floor_divide(i, q) * q + q/2)
# ---^-^---
嘿,感谢您的帮助,但现在我在这部分中有一个错误。对于在范围(1,高度+ 1)中的i: 对于在范围(1,宽度+ 1)中的j: y [i,j] y = np.zeros(img.size,dtype =“uint8”) = Q(img [i,j] +1) – Anuj
感谢您的帮助:) – Anuj
@Anuj我的荣幸 – percusse
嘿,我被困在最后一点,请如果你能帮忙。代码如下: – Anuj