我有以下代码:
import numpy as np
a=np.array([[1.1,5,100],[2.4,6,200],[3.3,7,300],[4.1,8,400],[4.9,9,500],[5.5,10,600],[6,5],700,[6.5,12,800],[7.2,20,900],[8,20,1000]])
b=np.max(a[:,0])#finds maximum value in 1st column(index=0)
if b > 5:
Do something
我希望代码识别数组第1列中第一行的值大于5,然后删除之后的行。只有当第1列中的最大值大于5时才会发生这种情况。结果数组c应该如下所示:
c=np.array([[1.1,5,100],[2.4,6,200],[3.3,7,300],[4.1,8,400],[4.9,9,500]])
答案 0 :(得分:3)
找到解决方案:
import numpy as np
a=np.array([[1.1,5,100],[2.4,6,200],[3.3,7,300],[4.1,8,400],[4.9,9,500],[5.5,10,600],[6,5],700,[6.5,12,800],[7.2,20,900],[8,20,1000]])
b=np.max(a[:,0])#finds maximum value in 1st column(index=0)
if b > 5:
c=a[a[:,0]<=5,:]
我找到了解决方案: