在我的代码中,我已将数据加载到数组中。在数组上循环时,每次执行else
时,amat
数组的数组值都会发生变化(仅适用于执行循环的那些i)。你知道吗
也就是说,for循环前的amat[i]
不等于for循环后的amat[i]
,因为i是执行else
语句的地方。你知道吗
这是我的代码片段。你知道吗
amat = np.loadtxt(infl)
for i,yentry in enumerate(amat):
depth = yentry[0]
if depth < dhigh:
if depth >= dlow:
if bint == 1:
mindepth = dlow
matline += yentry
count += 1
else:
avgmat = matline / float(count)
bavg[bint,:] = avgmat
depthfix = round((dlow + dhigh)/2,1)
bavg[bint,0] = depthfix
stringlist.append((' '.join(['%10.6f ']*len(avgmat))+'\n') % tuple(avgmat))
avgmat = yentry
matline = yentry
bint += 1
count = 1
dlow = dhigh
dhigh += step
是什么原因造成的?如您所见,我没有任何语句会影响amat的值。然而,很明显,有些事情正在发生。。。你知道吗
我知道没有完整的代码很难诊断,但是有人能想到可能导致这种情况的任何问题吗?我的数组如何在不应用任何操作的情况下进行修改?你知道吗
定义时:
在
else
块内部和之后:它实际上是在改变一行
amat
。因为matline
是对yentry
的引用,这是对一行amat
的引用。你知道吗为防止出现这种情况,可以通过创建副本来中断引用:
相关问题 更多 >
编程相关推荐