【发布时间】:2017-11-23 19:02:37
【问题描述】:
我有一个与检测器有关的问题,该检测器读取进入通道的光子数量以及它们进入检测器的时间,为了简单起见,我们假设它的通道 0 到 6。阵列 A 将保存通道,基本上是索引列表,虽然我可以很好地计算光子数,但我无法将时间存储在一个合理的容器中而没有循环(数据文件很大)。所以将数组 A 视为索引列表,将 B 视为时间。
A=np.array([3,0,4,2,4,1,6])
#so this just says channel 3 got one photon, channel 0 got one,
#channel 4 got two, 2 got one, 1 got one, channel 5 never got any so
#it doesn't show up, and 6 got one.
B=np.array([1.2,1.6,3.,.7,.1,.05,9.])
#so here B are the times and they say (by referencing A) that channel
#1 got a photon at .05s, channel 0 got its photon at 1.6s, channel 4
#got a photon at 3s and another at .1s etc.
#I would like to somehow store these times in a coo sparse array or
# perhaps just a regular array that would look like:
C=np.array([[1.6,0],[.05,0],[.7,0],[1.2,0],[.1,3.0],[0,0],[.9,0]])
#the zeros could be nans of course. It would be helpful if each row
# was ordered from earliest times to latest. This final array is
#of course ordered properly from 0 to 6 in terms of channels down
#the first axis (not in the random order that the index list was)
如果您不关心速度,这不是一个难题,但不幸的是,我最近所做的一切都需要快速。谢谢大家
【问题讨论】:
-
我在解释B数组时犯了一个令人困惑的错误,我更正了,对不起。
标签: python performance numpy indexing vectorization