Tensorflow 2
import tensorflow as tf
tensor = tf.Variable(10, dtype=tf.int32)
with tf.compat.v1.Session() as sess:
sess.run(tf.compat.v1.global_variables_initializer())
value = sess.run(tensor) #value 就是你想要的值
Pytorch
import torch
tensor = torch.tensor([1,2])
value = tensor.item()