1、 tensor与numpy转换
注意:tf 2以后不用session ,tensor转numpy直接 mm.numpy()就行
np.asarray([1,3,6,2]) #列表或元祖转array
# numpy to tensor
import numpy as np
data_numpy = np.ones(5)
mm = tf.convert_to_tensor(data_numpy)
with tf.Session() as sess:
print(mm.eval())
# tensor to numpy
with tf.Session() as sess:
print(kk.eval())
2、embedding_lookup、embedding_lookup_sparse使用
参考:https://www.jianshu.com/p/e8986d0ff4ff
import tensorflow as tf
# tf.enable_eager_execution() # 关键
# tf.enable_eager_execution(
# config=None,
# device_policy=None,
# execution_mode=None
# )
embedding = tf.constant(
[
[0.21,0.