Python值未正确附加到3D数组

时间:2019-02-04 18:48:19

标签: python arrays numpy

尝试用迭代值填充3D数组,但是只要循环结束,这些值似乎就会丢失。当我具有指定数组位置的值

dctArray[dctRow][dctColumn]

我尝试将其等同于3D阵列

dctArrayBlocks[i][dctRow][dctColumn] = dctArray[dctRow][dctColumn]

这很好,当我打印出来时,它很好并且具有正确的值(dctArrayBlocks [0] [0] [0]为1205)。但是,当我尝试打印整个数组时,这是不正确的。在这里:

[[  1.07300000e+03   1.90617212e+00   5.00208109e+00  -3.00240276e+00
    2.82842712e+00   1.12512565e+00   9.89537629e-01  -1.39738527e+00]
 [  9.98551802e-01  -1.35587613e+00  -1.41616626e+00   1.38806044e-02
    5.79485089e-01  -4.13036876e-01   1.44975210e-01   2.85262621e-01]
 [  2.37927142e+01  -2.03097102e+00  -2.11243687e+00   1.10874445e+00
    3.66268908e-01   3.47991879e-01   9.78553391e-01   2.32708288e-01]
 [  8.88756873e+00   6.35275667e-01   2.07200694e-01  -4.58464015e-01
   -1.03408662e+00   1.17558825e+00  -4.10718526e-01   7.56728301e-02]
 [  5.30330086e+00   1.01053364e-01   1.35299025e-01   4.69247507e-01
   -1.25000000e+00   7.02278523e-01  -3.26640741e-01   7.18462308e-01]
 [  1.74417891e+00   5.71491229e-01  -7.76269649e-01   9.98811555e-01
   -2.73383990e-02   9.23474911e-02   3.62498265e-01   6.78745550e-01]
 [  2.00792148e+00  -3.63013880e-02  -2.71446609e-01  -9.23433284e-01
   -4.22311599e-01  -6.84420366e-01   3.62436867e-01  -1.48161436e-01]
 [  1.31329760e+00   1.60262621e-01  -3.67637086e-02  -6.96207734e-01
    3.65118531e-01  -8.64253338e-01   4.99937678e-01   5.77868789e-01]]

不确定为什么我尝试在数组中打印单个值时是正确的,但是当我打印整个数组时,值不正确。这是完整的代码,感谢您的帮助!

    dctArray = np.zeros(shape = (8,8))

    Cu = 0.0
    Cv = 0.0

    dctArrayBlocks = np.zeros(shape = (4,8,8))

    for i in range(4):

        for dctRow in range(blockSize):

            for dctColumn in range (blockSize):

                dctSum = 0

                for row in range (blockSize):

                    for column in range (blockSize):

                        dctSum = dctSum + blocksList[i][row][column]*math.cos(((2.0*row+1)*dctRow*math.pi)/16.0)*math.cos(((2.0*column+1)*dctColumn*math.pi)/16.0)

                if(dctRow == 1):
                    cRow = 1/math.sqrt(2)

                else:
                    cRow = 1

                if(dctColumn == 1):
                    cColumn= 1/math.sqrt(2)

                else:
                    cColumn = 1

                dctArray[dctRow][dctColumn] = 1/4.0*cRow*cColumn*dctSum
                dctArrayBlocks[i][dctRow][dctColumn] = dctArray[dctRow][dctColumn]
                print(dctArrayBlocks[i][dctRow][dctColumn])
                #print(dctArrayBlocks)

        print(dctArrayBlocks[i])

0 个答案:

没有答案