如何使用循环读取存储在文件中的多维矩阵的值

我正在尝试读取存储在文件中的nxmxsx3矩阵的值,例如amat。我尝试:

amat=np.zeros([n,m,s,3])

ifile=open("input.dat","r")


for i in range(0,n - 1):
    for j in range(0,m - 1):
        for sind in range(0,s-1):
            amat[i,j,sind,0],amat[i,1],2]= ifile.read().split()

但它返回以下错误:

ValueError: too many values to unpack (expected 3)

有什么办法解决此问题吗?

wumao19910 回答:如何使用循环读取存储在文件中的多维矩阵的值

结果很简单:需要正确(使用split)读取每一行(使用readline)

Run
本文链接:https://www.f2er.com/3170052.html

大家都在问