Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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数组行时出现问题_Python_Numpy_Filtering_Conditional Statements - Fatal编程技术网

Python 按多个条件筛选numpy数组行时出现问题

Python 按多个条件筛选numpy数组行时出现问题,python,numpy,filtering,conditional-statements,Python,Numpy,Filtering,Conditional Statements,我想按多个条件筛选numpy数组。我发现 并在我的数据集上测试了切片方法,但得到了意想不到的结果。好吧,至少对我来说,它们是出乎意料的,因为我可能只是在理解按位运算符的功能或其他方面有问题:/ 只是为了让您了解数据: test.shape >>(222988, 2) stats.describe(all_output[:, 0]) >>DescribeResult(nobs=222988, minmax=(2.594e-05, 74.821), mean=11.106,

我想按多个条件筛选numpy数组。我发现 并在我的数据集上测试了切片方法,但得到了意想不到的结果。好吧,至少对我来说,它们是出乎意料的,因为我可能只是在理解按位运算符的功能或其他方面有问题:/

只是为了让您了解数据:

test.shape
>>(222988, 2)

stats.describe(all_output[:, 0])
>>DescribeResult(nobs=222988, minmax=(2.594e-05, 74.821), mean=11.106, variance=108.246, [...])

stats.describe(all_output[:, 1])
>>DescribeResult(nobs=222988, minmax=(0.001, 8.999), mean=3.484, variance=7.606, [...])
现在,进行一些基本筛选:

test1 = test[(test[:, 0] >= 30) & (test[:, 1] <= 2)] 

test1.shape
>>(337, 2)
test1=test[(test[:,0]>=30)和(test[:,1]>(337,2)
这些实际上是我不想在我的数据集中包含的行,所以如果我做我认为相反的事情

test2 = test[(test[:, 0] <= 30) & (test[:, 1] >= 2)] 

test2.shape
>>(112349, 2)
test2=test[(test[:,0]=2)]
test2.shape
>>(112349, 2)
我希望结果是(222651,2)。我猜我做错了一些让人尴尬的简单事情?这里有人能把我推向正确的方向吗

已经谢谢了!-M

not(p和q)=(not p)*或*(not q)
。无论如何,not操作符在so中

((测试[:,0]>=30)和(测试[:,1]2)) 两者都可以做你想做的事

test1 = test[~((test[:, 0] >= 30) & (test[:, 1] <= 2))]

test1=test[~(test[:,0]>=30)和(test[:,1]A和B的对立面不是A或notB,而>=的对立面是2)]
应该可以完成这项工作。这说明了这一点,谢谢!谢谢!现在我觉得自己真的很愚蠢,因为我以前甚至在代码中使用了~。但是谢谢你给我提供了一些关于德摩根定律的上下文!
test1 = test[~((test[:, 0] >= 30) & (test[:, 1] <= 2))]