我有一個python函數,它有兩個列表,在兩個輸入中查找對,其中兩個輸入都具有相同索引處的正值,並通過追加到每個列表創建兩個輸出列表這兩個正面價值。我有一個工作功能:用numpy高效獲得正值對
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?
使用[numpy.logical_and](http://docs.scipy.org/doc/numpy/reference/routines .logic.html)。 –
我們在這裏討論的名單有多大? – koukouviou
長度可能在100000左右。 – ayeayeron