deleting rows in numpy array

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

    This is similar to your original approach, and will use less space than unutbu's answer, but I suspect it will be slower.

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

    By the way, your line p.delete() doesn't work for me - ndarrays don't have a .delete attribute.

提交回复
热议问题