我有以下问题。我有一个数组(前3个元素是x,y,z坐标,第4个元素是时间,第5个元素是单元格ID(1-9)。现在我只想要每个时间点的每个第50或第100个元素FOR每个细胞ID。这不是重复的问题!因此对于细胞ID 1,我想要时间点为50,100,150的行,对于Cell ID2,时间点为50,100,150,等等!
示例数组
arr = np.array([['2.0', '29.0', '24.0', '0.0', '1'],
['0.0', '18.0', '4.0', '0.0', '2'],
['16.0', '9.0', '0.0', '9990.0', '7'],
['20.0', '23.0', '31.0', '9990.0', '8'],
['65.0', '30.0', '20.0', '0.0', '9']
['16.0', '9.0', '0.0', '9990.0', '9']])
答案 0 :(得分:1)
你可以这样做 -
# Convert the fourth col to int type
a = arr[:,3].astype(float).astype(int)
steps = [15,50] # Define step intervals
# Get time-stepped array intervaled at either of the elements from steps
range_arr = np.arange(a.max()+1)
r = range_arr[((np.arange(a.max()+1)[:,None]%steps)==0).any(1)]
# Get mask of matches. Index into input array for final output.
out = arr[np.in1d(a,r)]