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)
- 上一篇 »python numpy 判断ndarray 中是否有 nan
- 下一篇 »PHP数组对象互转