将numpy数组转换为字符串

时间:2019-01-03 23:07:05

标签: python arrays string numpy

我使用Numpy库并将句子(sents)转换为一个int32(words_idxs)数组,但我不知道如何使用Numpy来逆转此步骤。也就是说,将int32数组转换为一个句子。

def build_input_data(voc, sents, tags, tags_uni, cues, scopes, labels):

    words_idxs = [np.array([voc['w2idxs'][w] if w in voc['w2idxs'] else voc['w2idxs']["<UNK>"] for w in sent],dtype=np.int32) for sent in sents]
    tags_idxs = [np.array([voc['t2idxs'][t] for t in tag_sent],dtype=np.int32) for tag_sent in tags]
    tags_uni_idxs = [np.array([voc['tuni2idxs'][tu] for tu in tag_sent_uni],dtype=np.int32) for tag_sent_uni in tags_uni]
    y_idxs = [np.array([voc['y2idxs'][y] for y in y_array],dtype=np.int32) for y_array in labels]
    cues_idxs = [np.array([1 if c=="CUE" else 0 for c in c_array],dtype=np.int32) for c_array in cues]
    scope_idxs = [np.array([1 if s=="S" else 0 for s in s_array],dtype=np.int32) for s_array in scopes]

    return words_idxs, tags_idxs, tags_uni_idxs, cues_idxs, scope_idxs,  y_idxs

0 个答案:

没有答案