deleting rows in numpy array

后端 未结 6 1698
自闭症患者
自闭症患者 2020-12-01 00:01

I have an array that might look like this:

ANOVAInputMatrixValuesArray = [[ 0.96488889, 0.73641667, 0.67521429, 0.592875, 
0.53172222], [ 0.78008333, 0.59381         


        
6条回答
  •  庸人自扰
    2020-12-01 00:28

    The simplest way to delete rows and columns from arrays is the numpy.delete method.

    Suppose I have the following array x:

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

    To delete the first row, do this:

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

    To delete the third column, do this:

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

    So you could find the indices of the rows which have a 0 in them, put them in a list or a tuple and pass this as the second argument of the function.

提交回复
热议问题