小编And*_*tas的帖子

复制变量会改变原始变量吗?

我在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)

...
Run Code Online (Sandbox Code Playgroud)

如下所示,matriz尽管aux函数已更改了矩阵,但矩阵仍会发生变化solucoes().

矩阵之前:
[[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]]

python variables

48
推荐指数
3
解决办法
6万
查看次数

标签 统计

python ×1

variables ×1