Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 3.x numpy阵列中的滤波_Python 3.x_Numpy_Numpy Ndarray - Fatal编程技术网

Python 3.x numpy阵列中的滤波

Python 3.x numpy阵列中的滤波,python-3.x,numpy,numpy-ndarray,Python 3.x,Numpy,Numpy Ndarray,要根据仅使用numpy的条件筛选numpy数组 sample = ["aple","mangp", "orange"] np.where("p" in sample) Op: (array([], dtype=int64),) Expected OP: (array([1,1,0], dtype=int64),) 如果能指出我的错误,那就太好了 sample = ["aple", &qu

要根据仅使用numpy的条件筛选
numpy数组

sample = ["aple","mangp", "orange"]
np.where("p" in sample)

Op:

(array([], dtype=int64),)

Expected OP:

(array([1,1,0], dtype=int64),)
如果能指出我的错误,那就太好了

sample = ["aple", "mangp", "orange"]
np.where(["p" in s for s in sample])

(数组([0,1]),)

它对应于真实元素的索引

您的预期输出如下所示:

np.array(["p" in s for s in sample]).astype(int)