如何在python中仅保留满足阈值的某些行/列

如何在python中仅保留满足阈值的某些行/列,python,r,Python,R,因此,我只想保留满足阈值的某些行/列。 实际上,R中的代码只保留满足阈值的行和列: repeat { # Repeat whatever is in the brackets i <- sum(dim(M)) # Check the size of M M <- M[rowSums(M) >= 50, colSums(M) >= 15

因此,我只想保留满足阈值的某些行/列。 实际上,R中的代码只保留满足阈值的行和列:

repeat {                                       # Repeat whatever is in the brackets
  i <- sum(dim(M))                             # Check the size of M
  M <- M[rowSums(M) >= 50, colSums(M) >= 150]  # Retain only these rows/columns that meet the threshold
  if (sum(dim(M)) == i) break                  # If the size has not changed, break the loop
  }
repeat{#重复括号中的内容
i=150]#仅保留满足阈值的这些行/列
如果(sum(dim(M))==i)中断#如果大小没有改变,则中断循环
}
只是不知道如何将其转换为python。 提前谢谢

在R:

M = matrix(c(70,10,20,90,30,15,80,50,40,20,50,5),ncol=3)                           
i = dim(M)
M <- M[rowSums(M) >= 50, colSums(M) >= 150]
M
     [,1] [,2]
[1,]   70   30
[2,]   20   80
[3,]   90   50

dim(M)
[1] 3 2

i
[1] 4 3

identical(i,dim(M))
[1] FALSE

你能澄清一下
M
是什么吗?您能否澄清预期的行为是什么和/或您在Python中尝试重新创建它时做了什么?
import numpy as np

M = np.array([[70,30,40],[10,15,20],[20,80,50],[90,50,5]])
i = M.shape

M = M[M.sum(axis=1)>=50][:,M.sum(axis=0)>=150]
array([[70, 30],
       [20, 80],
       [90, 50]])

M.shape == i
Out[25]: False