Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:Numpy数组,每100个时间点取一个单元格ID_Python_Arrays_Numpy_Scipy - Fatal编程技术网

Python:Numpy数组,每100个时间点取一个单元格ID

Python:Numpy数组,每100个时间点取一个单元格ID,python,arrays,numpy,scipy,Python,Arrays,Numpy,Scipy,我有以下问题。我有一个数组,前3个元素是x,y,z坐标,第4个元素是时间,第5个元素是单元格ID 1-9。现在我只需要每个单元格ID的每个时间点的第50或100个元素。这不是重复的问题!所以对于单元ID 1,我想要时间点为50100150的行,对于单元ID 2,我想要时间点为50100150的行,依此类推 示例数组 你可以这样做- # Convert the fourth col to int type a = arr[:,3].astype(float).astype(int) steps

我有以下问题。我有一个数组,前3个元素是x,y,z坐标,第4个元素是时间,第5个元素是单元格ID 1-9。现在我只需要每个单元格ID的每个时间点的第50或100个元素。这不是重复的问题!所以对于单元ID 1,我想要时间点为50100150的行,对于单元ID 2,我想要时间点为50100150的行,依此类推

示例数组


你可以这样做-

# 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)]

数组真的包含字符串吗?如果是这样,为什么?您可以使用arr.view['xyz',arr.dtype,3't',arr.dtype,'cell',arr.dtype].squeak-1.astype['xyz',float,3't',float,'cell',arr.dtype]将其转换为更有用的类型,因此,对于单元格ID 9,您在时间点0处会有两个匹配项?哦,是的,sry是个糟糕的例子!,我编辑了ithmm,这很奇怪,但这让我每150次看到我的问题。我的时间步数以秒为单位15@Varlor查看编辑以涵盖15秒和50秒步骤。
# 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)]