代码如下:
for oneRow in range(rowcnt):
for oneCol in range(colcnt):
r, g, b = ndarr[oneRow][oneCol]
h, s, v = colorsys.rgb_to_hsv(r/255, g/255, b/255)
h = h * 360
l = self._hsv2L(h, s, v)
LVector[l/6] +=1
lsum =sum(LVector)
result = [v * 1.0/lsum for v in LVector]
代码报错如下:
LVector[l/6] +=1
TypeError: list indices must be integers or slices, not float
也可以写成LVector[l//6] +=1
可以改成 LVector[int(l/6)] +=1