大家早上好
我試圖在變數 x 和 y 中插入由 itertools.combination 函式生成的元組串列中的索引 [0] 和索引1
在這些鏈接“itertools.combinations”物件不是標化的我發現,從組合物件不標化,并會想知道,如果看到一只方式來獲得單獨的元組索引功能
a = [10,11,12,13,14,15]
b = combinations(a,2)
x= b[0]
y= b[1]
conditions = [df[f'sma_{x}'] > df[f'sma_{y}'],
df[f'sma_{x}'] < df[f'sma_{y}']]
choices = [1, -1]
df[f'sma_{x} & sma_{y}'] = np.select(conditions, choices, default=0)
uj5u.com熱心網友回復:
itertools.combinations 回傳一個生成器運算式。
如果要訪問結果的索引,則combinations必須使用以下命令“使用”它list:
a = [10,11,12,13,14,15]
b = list(combinations(a,2))
x= b[0]
y= b[1]
conditions = [df[f'sma_{x}'] > df[f'sma_{y}'],
df[f'sma_{x}'] < df[f'sma_{y}']]
choices = [1, -1]
df[f'sma_{x} & sma_{y}'] = np.select(conditions, choices, default=0)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/327220.html
上一篇:為什么我收到錯誤“NoSuchMethodError:Class'List<List<int>>'hasnoinstancegetter'shap
