【发布时间】:2018-01-24 09:18:15
【问题描述】:
我想从 2D 事件数组 (x,y,t) 中增加计数器的 3D 矩阵 (nparray) 下面的代码有效:
TOF_cube=np.zeros((324,324,4095),np.int32) #initialise a 3d array for whole data set
data = np.fromfile(f, dtype='<i2', count=no_I16) #read all events, x,y,t as 1D array
data=data.reshape(events,cols)
xpos=data[:,0]
ypos=data[:,1]
tpos=data[:,2]
i=0
while i < events:
TOF_cube[xpos[i],ypos[i],tpos[i]] += 1
i+=1
为了使用切片和索引,我用
替换了我的 while 循环 TOF_cube[xpos,ypos,tpos] += 1
但不是复制正确的 4365520 个事件(通过 while 循环并独立检查),我只记录 4365197。
为什么切片方法会丢失事件?
我在 while 循环中使用完全相同的切片并作为索引的“参数”。
【问题讨论】:
-
每种方法的
TOF_cube.max()是什么?
标签: python numpy indexing slice