import tensorflow as tf
import numpy as np
Y_c = [[1],[0],[0],[0],[0],[1]]
Y_c = tf.convert_to_tensor(Y_c)
Y_c = [[‘red’ if y else ‘blue’] for y in Y_c]
print(Y_c)
out:
[[‘red’], [‘blue’], [‘blue’], [‘blue’], [‘blue’], [‘red’]]
1.首先必须转换为tensor数据类型
2.此代码可展开为:
Y_c = [[1],[0],[0],[0],[0],[1]]
Y_c = tf.convert_to_tensor(Y_c)
temp = []
for y in Y_c:
if y == 1:
temp.append(‘red’)
else:
temp.append(“blue”)
Y_c = temp
print(Y_c)