【发布时间】:2015-05-11 01:46:45
【问题描述】:
我有一个 python 函数,它接受两个列表,在两个输入中查找在同一索引处都有正值的对,并通过附加到这两个正值中的每一个来创建两个输出列表。我有一个工作函数:
def get_pairs_in_first_quadrant(x_in, y_in):
"""If both x_in[i] and y_in[i] are > 0 then both will appended to the output list. If either are negative
then the pair of them will be absent from the output list.
:param x_in: A list of positive or negative floats
:param y_in: A list of positive or negative floats
:return: A list of positive floats <= in length to the inputs.
"""
x_filtered, y_filtered = [], []
for x, y in zip(x_in, y_in):
if x > 0 and y > 0:
x_filtered.append(x)
y_filtered.append(y)
return x_filtered, y_filtered
如何使用 numpy 加快速度?
【问题讨论】:
-
我们在这里讨论的列表有多大?
-
长度可能在 100 000 左右。
标签: python logging numpy filter