我试图将几个矩阵附加到矢量。我的目标只是创建一个矩阵向量。
result_array = []
for prob in probs:
countprobstats(values)
result_array.append(values)
问题是看起来它正在用函数获得的值替换先前的值,例如:
来自功能:[[6.9e-05,0.000233],[40836.0,137370.0]]
Vector:[[[6.9e-05,0.000233],[40836.0,137370.0]]]
来自功能:[[0.00011,0.000371],[46236.0,155531.0]]
Vector:[[[0.00011,0.000371],[46236.0,155531.0]],[[0.00011,0.000371],[46236.0,155531.0]]
来自功能:[[0.000148,0.000498],[55658.0,186734.0]]
载体:[[[0.000148,0.000498],[55658.0,186734.0]],[[0.000148,0.000498],[55658.0,186734.0]],[[0.000148,0.000498],[55658.0,186734.0]]] p>
有什么问题? 感谢
答案 0 :(得分:1)
看起来values
总是是同一个对象,因为countprobstats
就地修改了它,而你正在将指针复制到它实际数据。
要解决此问题,请明确复制数据:
something.append(values.copy())
...或让countprobstats
返回副本,而不是进行就地修改。