remove zero lines 2-D numpy array

前端 未结 3 1985
旧时难觅i
旧时难觅i 2020-12-01 04:07

I run a qr factorization in numpy which returns a list of ndarrays, namely Qand R:

>>&         


        
3条回答
  •  感情败类
    2020-12-01 05:11

    If you want to eliminate rows that have negligible entries, i'd use np.allclose.

    zero_row_indices = [i for i in r.shape[0] if np.allclose(r[i,:],0)]
    nonzero_row_indices =[i for i in r.shape[0] if not np.allclose(r[i,:],0)]
    r_new = r[nonzero_row_indices,:]
    

提交回复
热议问题