tensorflow2.0 numpy.ndarray 与tenor直接互转

1、代码参考
import numpy as np
import tensorflow as tf

a = np.random.random((5,3))
b = np.random.randint(0,9,(3,1))
c = tf.tensordot(a.astype(np.float),b.astype(np.float),axes=1)

tensor 转ndarray

dn = c.numpy()
print(dn)

ndarray转tensor

tn = tf.convert_to_tensor(dn)
print(tn)

转载于:https://www.cnblogs.com/wuzaipei/p/10956279.html

你可能感兴趣的:(深度学习,numpy,深度学习,tensorflow,python)