TensorFlow2——tensor 转为 numpy

TensorFlow2 将tensor转化为numpy数组:

import tensorflow as tf
a = tf.constant([[1, 2],
                 [3, 4]])
print(a)

# Obtain numpy value from a tensor:
print(a.numpy())

numpy 数组转化为tensor:

import tensorflow as tf
import numpy as np
a = np.array([1, 2])
a= tf.convert_to_tensor(a)

你可能感兴趣的:(TensorFlow,2)