我想删除numpy.array中的选定列。这是我的工作:
n [397]: a = array([[ NaN, 2., 3., NaN],
.....: [ 1., 2., 3., 9]])
In [398]: print a
[[ NaN 2. 3. NaN]
[ 1. 2. 3. 9.]]
In [399]: z = any(isnan(a), axis=0)
In [400]: print z
[ True False False True]
In [401]: delete(a, z, axis = 1)
Out[401]:
array([[ 3., NaN],
[ 3., 9.]])
在此示例中,我的目标是删除所有包含NaN的列。我希望最后一个命令会导致:
array([[2., 3.],
[2., 3.]])
我怎样才能做到这一点?
numpy
,而不是scipy
。docs.scipy.org/doc/numpy/reference/generation/numpy.delete.html