小编Rod*_*vas的帖子

更改二维数组元素的值会更改整个列

当我打印我的arr值时,我得到了二维数组的正确值,但是当我退出 while 循环时,我的值都是错误的。

我不确定我做错了什么。

    #num runs
    n = 4

    x = np.linspace(-1,1,n)
    y = np.linspace(-1,1,n)
    x1,y1 = np.meshgrid(x, y)

    l = np.linspace(0,1000,n)
    x = np.linspace(-1,1,n)
    p1,p2 = np.meshgrid(l,l)

    w020 = 5*(y1**2+x1**2)

    row, cols = (n,n)
    arr = [[0]*cols]*row
  
    i = 0
    p = 0
    while i < n:
        i += 1
        p=0
        while p < n:
            arr[i-1][p] = 2+2*math.cos(2*math.pi*w020[i-1,p])
            p += 1
    print(arr)       
Run Code Online (Sandbox Code Playgroud)

python performance numpy while-loop optics-algorithm

4
推荐指数
1
解决办法
3075
查看次数