张量(Tensor):多维数组(列表) 阶:张量的维度
张量可以表示0阶到n阶数组(列表)
数据类型:
tf.int, tf.float…
tf.int 32 , tf.float 32, tf.float 64
tf.bool
tf.constant([True,False])
tf.string
tf.constant(“Hello,world!”)
如何创建一个Tensor
tf.constant(张量内容,dtype=数据类型(可选))
import tensorflow as tf
a = tf.constant([1,5],dtype = tf.int64) #一维数据,两个元素
print(a)
print(a.dtype) #几个逗号几个维度(阶)
print(a.shape)
输出结果:
将numpy的数据类型转换为Tensor数据类型
tf.convert_to_tensor(数据名,dtype=数据类型(可选))
import tensorflow as tf
import numpy as np
a = np.arange(0,5)
b = tf.convert_to_tensor(a,dtype=tf.int64)
print(a)
print(b)
输出结果: