简体   繁体   English

如何将array([array([…],type = float32)],[array([…],type = float32)])转换为array([…],[…])?

[英]How to convert array([array([ …],type=float32)],[array([ …],type=float32)]) to array([…],[…])?

Here is my code: 这是我的代码:

def extract_doc2vec(doc, w2v):
vecs = [w2v[word] for word in doc if word in w2v]
if len(vecs) > 0:
    vecs = np.asarray(vecs).sum(axis=0)
    return vecs
y = newsgroups_all['target']

x= []

for doc in newsgroups_all['data']:
    edv = extract_doc2vec(list(gensim.utils.tokenize(doc)),model.wv)
    x.append(edv)

I have to convert retrain_doc which can be fit into 我必须将retrain_doc转换成适合的格式

for train_index, test_index in sssd.split(x, y):
   X_train, X_test = x[train_index], x[test_index]
   y_train, y_test = y[train_index], y[test_index]

将列表x转换为数据帧,然后将其转换为numpy数组并应用shuffle拆分

data = pd.DataFrame(x).to_numpy()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM