Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.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 基于另一个数组的数据数组的子集_Python_Numpy_Multidimensional Array - Fatal编程技术网

Python 基于另一个数组的数据数组的子集

Python 基于另一个数组的数据数组的子集,python,numpy,multidimensional-array,Python,Numpy,Multidimensional Array,我有一个整数数组,每个整数需要按4分组。我还想根据另一个标准来选择它们,start

我有一个整数数组,每个整数需要按4分组。我还想根据另一个标准来选择它们,start
但是它抱怨start对数组进行布尔索引的正确方法如下:

>>> import numpy as np
>>> a=np.random.randint(0,20,size=24)
>>> b=np.arange(24)
>>> b[(8<a)&(a<15)] #rather than 8<a<15
array([ 3,  5,  6, 11, 13, 16, 17, 18, 20, 21, 22, 23])

数组布尔索引的正确方法应如下所示:

>>> import numpy as np
>>> a=np.random.randint(0,20,size=24)
>>> b=np.arange(24)
>>> b[(8<a)&(a<15)] #rather than 8<a<15
array([ 3,  5,  6, 11, 13, 16, 17, 18, 20, 21, 22, 23])
这个怎么样

import numpy as np

arr = np.arange(32)
t = np.arange(300, 364, 2)
start = 310
stop = 352
mask = np.logical_and(start < t, t < stop)
print mask
print arr[mask].reshape((-1,4))
我在整形之前做了掩蔽,不确定这是否是你想要的。关键部分可能是逻辑和。

这个怎么样

import numpy as np

arr = np.arange(32)
t = np.arange(300, 364, 2)
start = 310
stop = 352
mask = np.logical_and(start < t, t < stop)
print mask
print arr[mask].reshape((-1,4))

我在整形之前做了掩蔽,不确定这是否是你想要的。关键部分可能是逻辑和。

什么是开始、停止和t?它们中的一个或多个应该取某个向量的值吗?t是一个数字数组,start和stop都是数字。什么是start、stop和t?它们中的一个或多个应该取某个向量的值吗?t是一个数字数组,start和stop都是数字。