我有一个简单的Python问题,但非常奇怪。
def estExt(matriz,erro):
# (1) Determinar o vector X das soluções
print ("Matrix after:");
print(matriz);
aux=matriz;
x=solucoes(aux); # IF aux is a copy of matrix, why the matrix is changed??
print ("Matrix before: ");
print(matriz)
...
正如您在下面看到的那样,矩阵 matriz
在函数 solucoes()
更改的是 aux
,但实际上矩阵被更改了。
修改前的矩阵:
[[7, 8, 9, 24], [8, 9, 10, 27], [9, 10, 8, 27]]
修改后的矩阵:
[[7, 8, 9, 24], [0.0, -0.14285714285714235, -0.2857142857142847, -0.42857142857142705],
[0.0, 0.0, -3.0, -3.0000000000000018]]
a
指向一个不同的对象(整数3
),但是没有改变b
,所以b
仍然指向1
。 - kindalldict
结构,你可能需要使用dictionary.copy()
。 - xtonousou