张量(Tensor):多维数组(列表) 阶:张量的维数
张量可以表示0阶到n阶数组(列表)
基本的数据类型
tf.int,tf.float
tf.bool
tf.string
生成一个张量
- 如何创建一个张量
用法:tf.constant(张量内容,dtype=数据类型(可选))
例子:
import tensorflow as tf
#创建一个张量
a = tf.constant([1,5],dtype = tf.int64)
print(a)
print(a.dtype)
print(a.shape)
输出结果:
tf.Tensor([1 5], shape=(2,), dtype=int64) #有几个逗号说明是几维张量 这个是一个一维张量,里面有两个值1和5
<dtype: 'int64'>
- 将numpy的数据类型转换为Tensor数据类型
用法:tf.convert_to_tensor(数据名,dtype=数据类型(可选))
例子:
import tensorflow as tf
import numpy as np
a = np.arange(0,5