Skip to content

Instantly share code, notes, and snippets.

@lartpang
Created October 9, 2018 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lartpang/6aeb2c685d6120c1db6ec9b105368fa8 to your computer and use it in GitHub Desktop.
Save lartpang/6aeb2c685d6120c1db6ec9b105368fa8 to your computer and use it in GitHub Desktop.
导入文件/列表转换字符串/字符转化ascii码/独热编码/numpy存储npy
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