Scikit-learn
库有一个数据聚类的好例子 - stock market structure。它在美国股票内运作良好。但是当增加其他市场的代码时,numpy
的错误表明阵列应该具有相同的大小 - 例如,德国的股票有不同的交易日历。过滤器numpy元组数组
好,后引号下载我想补充制剂共享日期:
quotes = [quotes_historical_yahoo_ochl(symbol, d1, d2, asobject=True)
for symbol in symbols]
def intersect(list_1, list_2):
return list(set(list_1) & set(list_2))
dates_all = quotes[0].date
for q in quotes:
dates_symbol = q.date
dates_all = intersect(dates_all, dates_symbol)
然后我卡与过滤元组的numpy的阵列。下面是一些尝试:
# for index, q in enumerate(quotes):
# filtered = [i for i in q if i.date in dates_all]
# quotes[index] = np.rec.array(filtered, dtype=q.dtype)
# quotes[index] = np.asanyarray(filtered, dtype=q.dtype)
#
# quotes[index] = np.where(a.date in dates_all for a in q)
#
# quotes[index] = np.where(q[0].date in dates_all)
如何将过滤器应用于numpy的阵列或如何真正转换的记录(过滤后)列表回numpy
的recarray
?
报价[0] .dtype:
'(numpy.record, [('date', 'O'), ('year', '<i2'), ('month', 'i1'), ('day', 'i1'), ('d', '<f8'), ('open', '<f8'), ('close', '<f8'), ('high', '<f8'), ('low', '<f8'), ('volume', '<f8'), ('aclose', '<f8')])'
报价[0] .shape:
<class 'tuple'>: (261,)
By arra y的元组我怀疑你的意思是一个'结构化数组'(或'recarray')。如果是这样,我们想知道阵列的“形状”和“dtype”。 – hpaulj
感谢您的留言。添加! –