使用numpythonically过滤矩阵时返回所有列

使用numpythonically过滤矩阵时返回所有列,python,numpy,Python,Numpy,我已经尝试了几种方法,但无法恢复这两列。过滤可以工作,但只返回一列 import numpy as np <<<<read in some data, now get counts>>>> unique, counts = np.unique(data[0::,2], return_counts=True) x = np.asmatrix((unique, counts)) x = x.astype(np.int).T print x 我想筛选第

我已经尝试了几种方法,但无法恢复这两列。过滤可以工作,但只返回一列

import numpy as np
<<<<read in some data, now get counts>>>>
unique, counts = np.unique(data[0::,2], return_counts=True)
x = np.asmatrix((unique, counts))
x = x.astype(np.int).T
print x
我想筛选第二列>3

y = x[x[:,1] > 3,].T
print y
我现在只有第一列

[[100003]]
为什么我得不到

[[100003     4]]

您可以考虑使用<代码> ASStase<代码>而不是<代码> ASMask<代码>:

x = np.asarray((unique, counts))
那么它应该和你一样工作

当我在python 3.4/numpy 1.10.1上运行代码时,如果我使用
asmatrix
我会得到:

>>> x = np.asmatrix((unique, counts))
>>> x = x.astype(np.int).T
>>> y = x[x[:,1] > 10,].T
/usr/local/lib/python3.4/dist-packages/numpy/matrixlib/defmatrix.py:318: 
VisibleDeprecationWarning: boolean index did not match indexed array along dimension 1;
dimension is 2 but corresponding boolean dimension is 1
  out = N.ndarray.__getitem__(self, index)

您可以考虑使用<代码> ASStase<代码>而不是<代码> ASMask<代码>:

x = np.asarray((unique, counts))
那么它应该和你一样工作

当我在python 3.4/numpy 1.10.1上运行代码时,如果我使用
asmatrix
我会得到:

>>> x = np.asmatrix((unique, counts))
>>> x = x.astype(np.int).T
>>> y = x[x[:,1] > 10,].T
/usr/local/lib/python3.4/dist-packages/numpy/matrixlib/defmatrix.py:318: 
VisibleDeprecationWarning: boolean index did not match indexed array along dimension 1;
dimension is 2 but corresponding boolean dimension is 1
  out = N.ndarray.__getitem__(self, index)

当我运行你的代码时,我得到了你想要的结果。当我运行你的代码时,我得到了你想要的结果。Old
numpy
在没有警告的情况下执行此二维布尔索引。要选择
矩阵的行
x
,索引需要是1d数组,例如
(x[:,1]>10)。A1
。这是另一种情况,
np.matrix
有一些隐藏的陷阱。首先升级到1.10.4。然后切换到阵列。然后换了几行
x=np.asarray((唯一,计数)).T
,然后
x=x.astype(np.int)
然后
打印x[x[0:,1]>3]
,它成功了!Old
numpy
在没有警告的情况下执行此二维布尔索引。要选择
矩阵的行
x
,索引需要是1d数组,例如
(x[:,1]>10)。A1
。这是另一种情况,
np.matrix
有一些隐藏的陷阱。首先升级到1.10.4。然后切换到阵列。然后换了几行
x=np.asarray((唯一,计数)).T
,然后
x=x.astype(np.int)
然后
打印x[x[0:,1]>3]
,它成功了!