a = numpy.array(a) # ensure its a numpy array
print a[a[:,-1]=="p"]
把它分解
mask = a[:,-1]=="p" #gives an array of True/False that is the same as the array, based on if last char is "p"
a[mask] #indexes into the original array returning only the rows that end with "p"
你可以用过滤器来解决这个问题。你知道吗
上面的结构假设您处理的是一个列表列表(数组数组),但是元组和字典也应该如此。你知道吗
以下是对过滤器函数的引用: https://docs.python.org/2/library/functions.html#filter
这在python中很容易实现。你知道吗
你可以这样做:
简单的方法是使用numpy布尔索引,如下所示
把它分解
相关问题 更多 >
编程相关推荐