使用 tensorflow 将tensor 转换为numpy
可以使用 numpy() 方法将 TensorFlow 的 tensor 转换为 NumPy 数组。例如:
import tensorflow as tf
import numpy as np
# 创建一个 TensorFlow tensor
t = tf.constant([[1, 2], [3, 4]])
# 将 tensor 转换为 NumPy 数组
n = t.numpy()
print(n)
输出:
array([[1, 2],
[3, 4]], dtype=int32)
原文地址: https://www.cveoy.top/t/topic/bKaw 著作权归作者所有。请勿转载和采集!