deleting rows in numpy array

后端 未结 6 1693
自闭症患者
自闭症患者 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:26

    Here's a one liner (yes, it is similar to user333700's, but a little more straightforward):

    >>> 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]])
    

    By the way, this method is much, much faster than the masked array method for large matrices. For a 2048 x 5 matrix, this method is about 1000x faster.

    By the way, user333700's method (from his comment) was slightly faster in my tests, though it boggles my mind why.

提交回复
热议问题