到目前为止,我所犯的所有“错误”都是我失踪的小事,希望这就是这种情况。我决定使用NUMPY数组主要用于阵列大小调整功能。我注意到导入它需要一段时间,但它基本上是我需要的,所以乞丐不能选择。无论如何,在尝试从数组中“删除”项目并通过“插入”用新数据替换它时,我仍然有一个包含全零的数组。所以,我很茫然。我知道[archstartred],[archstartgrn]和[archstartblu]的值是正确的,因为我在生成它们时打印它们。为什么值不会填充到数组中?这是我的代码:
#Frame Creation
from numpy import *
frames=array([0 for i in range (0,workingframes*archnodes*3)])
frames.resize(archnodes*3, workingframes)
#Frame Population
for f in range (0, workingframes):
if f<=(workingframes/2):
for x in range (0, archnodes):
delete(frames,[x+f])
insert(frames,[x+f],(archstartred[x]))
print archstartred[x]
delete(frames,[x+f+workingframes])
insert(frames,[x+f+workingframes],(archstartgrn[x]))
print archstartgrn[x]
delete(frames,[x+f+workingframes*2])
insert(frames,[x+f+workingframes*2],(archstartblu[x]))
print archstartblu[x]
print frames
raw_input('Press control c') #stop/troubleshoot program
for y in range (0, nodesperframe):
archstartred.pop()
archstartgrn.pop()
archstartblu.pop()
archstartred.insert(0, backred)
archstartgrn.insert(0, backgrn)
archstartblu.insert(0, backblu)
archstartred = [int(value) for value in archstartred]
archstartgrn = [int(value) for value in archstartgrn]
archstartblu = [int(value) for value in archstartblu]
else:
for y in range (0, nodesperframe):
archstartred.pop(0)
archstartgrn.pop(0)
archstartblu.pop(0)
archstartred.append(backred)
archstartgrn.append(backgrn)
archstartblu.append(backblu)
archstartred = [int(value) for value in archstartred]
archstartgrn = [int(value) for value in archstartgrn]
archstartblu = [int(value) for value in archstartblu]
for x in range (0, archnodes):
delete(frames,[x+f])
insert(frames,[x+f],(archstartred[x]))
delete(frames,[x+f+workingframes])
insert(frames,[x+f+workingframes],(archstartgrn[x]))
delete(frames,[x+f+workingframes*2])
insert(frames,[x+f+workingframes*2],(archstartblu[x]))
答案 0 :(得分:2)
numpy函数insert
和delete
返回副本而不是就地发生。将结果分配回frames
而不是丢弃它。