Python错误numpy.int32对象不可编辑

Python错误numpy.int32对象不可编辑,python,numpy-ndarray,Python,Numpy Ndarray,我有一个下面的python代码,用于检测帧中的人。一旦检测到,它将获得人物的边界框,即person\u box。从person\u框我可以获得边界框的startX、startY和宽度高度。但在下面的代码中,在for循环中,我得到了错误,因为numpy.int32对象不可编辑 person_box = person_detections[0, 0, i, 3:7] * np.array([W, H, W, H]) person_box = person_box.astype(int) print(

我有一个下面的python代码,用于检测帧中的人。一旦检测到,它将获得人物的边界框,即
person\u box
。从
person\u框
我可以获得边界框的
startX、startY
宽度高度
。但在下面的代码中,在for循环中,我得到了错误,因为
numpy.int32对象不可编辑

person_box = person_detections[0, 0, i, 3:7] * np.array([W, H, W, H])
person_box = person_box.astype(int)
print(person_box)
(startX, startY, endX, endY) = person_box.astype("int")
width = endX - startX
height = endY - startY

for (startX, startY, width, height) in person_box:
    person_box = np.array([startX, startY, startX + width, startY + height])
输出

[159 156 451 431]

我不能很好地理解错误,因为我对numpy阵列没有太多经验。请帮忙。谢谢。

for
循环将迭代
person\u框
,并逐个参数传递参数。您正在尝试拆分参数并将其分配给
startX,startY,width,height
中的
for(startX,startY,width,height)in person\u框:
您可以尝试:

person_box = np.array([person_box [0], person_box[1] , person_box[0] + person_box[2] , person_box[1] + person_box[3] ])


显示回溯
startX = person_box[0]
startY = person_box[1]
width = person_box[2]
height = person_box[3]
person_box = np.array([startX, startY, startX + width, startY + height])