Created
October 9, 2018 09:08
-
-
Save lartpang/6aeb2c685d6120c1db6ec9b105368fa8 to your computer and use it in GitHub Desktop.
导入文件/列表转换字符串/字符转化ascii码/独热编码/numpy存储npy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from keras.utils import np_utils | |
# 导入测试标签 | |
y_label = [] | |
with open('label.txt', 'r') as label_file: | |
y_label = label_file.read().split() | |
print(y_label) | |
y_label_new = ''.join(y_label) | |
print(y_label_new) | |
y_label_new_new = np.zeros((len(y_label_new), )) | |
for i in range(len(y_label_new)): | |
y_label_new_new[i] = ord(y_label_new[i]) - 65 | |
print(y_label_new_new) | |
y_test_oh = np_utils.to_categorical(y_label_new_new, 3) | |
np.save('y_test.npy', y_test_oh) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment