# 删除numpy数组中的行

``ANOVAInputMatrixValuesArray = [[ 0.96488889, 0.73641667, 0.67521429, 0.592875, 0.53172222], [ 0.78008333, 0.5938125, 0.481, 0.39883333, 0.]]` `

` `NumNonzeroElementsInRows = (ANOVAInputMatrixValuesArray != 0).sum(1)` `

` `for q in range(len(NumNonzeroElementsInRows)): if NumNonzeroElementsInRows[q] < NumNonzeroElementsInRows.max(): p.delete(ANOVAInputMatrixValuesArray, q, axis=0)` `

` `x = array([[1,2,3], [4,5,6], [7,8,9]])` `

` `x = numpy.delete(x, (0), axis=0)` `

` `x = numpy.delete(x,(2), axis=1)` `

` `>>> import numpy as np >>> arr = np.array([[ 0.96488889, 0.73641667, 0.67521429, 0.592875, 0.53172222], [ 0.78008333, 0.5938125, 0.481, 0.39883333, 0.]]) >>> print arr[arr.all(1)] array([[ 0.96488889, 0.73641667, 0.67521429, 0.592875 , 0.53172222]])` `

` `>>> import numpy as np >>> p = np.array([[1.5, 0], [1.4,1.5], [1.6, 0], [1.7, 1.8]]) >>> p array([[ 1.5, 0. ], [ 1.4, 1.5], [ 1.6, 0. ], [ 1.7, 1.8]]) >>> nz = (p == 0).sum(1) >>> q = p[nz == 0, :] >>> q array([[ 1.4, 1.5], [ 1.7, 1.8]])` `

numpy提供了一个简单的函数来完成同样的事情：假设你有一个被屏蔽的数组“a”，调用numpy.ma.compress_rows（a）将删除包含一个被屏蔽值的行。 我想这样的速度要快得多