
import tensorflow as tf
import numpy as np
a = np.arange(0,5)
b = tf.convert_to_tensor(a,dtype=tf.int64) #将numpy数据格式转换为tensor格式
print("a:",a)
print("b:",b)
"""
a: [0 1 2 3 4]
b: tf.Tensor([0 1 2 3 4], shape=(5,), dtype=int64)
"""
本文演示了如何使用Python的NumPy库创建一维数组,并将其转换为TensorFlow张量。通过具体代码实例,展示了从NumPy数组到TensorFlow张量的转换过程及其输出结果。

import tensorflow as tf
import numpy as np
a = np.arange(0,5)
b = tf.convert_to_tensor(a,dtype=tf.int64) #将numpy数据格式转换为tensor格式
print("a:",a)
print("b:",b)
"""
a: [0 1 2 3 4]
b: tf.Tensor([0 1 2 3 4], shape=(5,), dtype=int64)
"""
6万+

被折叠的 条评论
为什么被折叠?
