TensorFlow(张量)

在数学里,张量是一种几何实体,广义上表示任意形式的数据,张量可以这么理解
0阶张量(rank) == 标量(scalar)
1阶张量(rank) == 向量(vector)
2阶张量(rank) == 矩阵(matrix)
3阶张量(rank) == 立方(tensor)
n阶张量。。。只能凭空想了

TensorFlow文档中使用了三种记号来方便地描述张量的维度:阶,形状以及维数.下表展示了他们之间的关系:

形状维数实例
0[ ]0-D一个 0维张量. 一个纯量.
1[D0]1-D一个1维张量的形式[5].
2[D0, D1]2-D一个2维张量的形式[3, 4].
3[D0, D1, D2]3-D一个3维张量的形式 [1, 4, 3].
n[D0, D1, ... Dn]n-D一个n维张量的形式 [D0, D1, ... Dn].

张量,在tensorflow中表示某种相同数据类型和多维数组
重要的属性
1 数据类型(浮点型,整形,字符串)
2 数组形状(各个维度的大小)
张量的形状很重要,计算的时候必须确定形状
张量的形状不一定要在编译时确定(形状不一定确定,跟我们的输入数据有关),可以在运行的时候通过形状推断计算的出

那张量到底是什么?
1张量用来表示多维数据的。
2张量是执行操作时的输入或者输出的数据

 

Tensorflow 特别的张量
tf.constant   常量(不可改变)
tf.placeholder   占位符
tf.Variable   变量

#0阶张量 分别创建 字符串 整数 浮点数 复数
mammal = tf.Variable("Elephant",tf.string)
ignition = tf.Variable(451,tf.int16)
floating = tf.Variable(3.1415926,tf.float64)
its_complicated = tf.Variable(12.3 - 4.85j,tf.complex64)


(<tf.Variable 'Variable_4:0' shape=() dtype=string_ref>,
 <tf.Variable 'Variable_5:0' shape=() dtype=int32_ref>,
 <tf.Variable 'Variable_6:0' shape=() dtype=float32_ref>,
 <tf.Variable 'Variable_7:0' shape=() dtype=complex128_ref>)

#1阶张量
mystr = tf.Variable(["Hello","World"],tf.string)
numbers = tf.Variable([1,2,3],tf.int16)
float_number = tf.Variable([1.1,2.2,3.3],tf.float64)
complicated = tf.Variable([12.3 - 4.85j,1 - 23.45j],tf.complex64)

(<tf.Variable 'Variable_8:0' shape=(2,) dtype=string_ref>,
 <tf.Variable 'Variable_9:0' shape=(3,) dtype=int32_ref>,
 <tf.Variable 'Variable_10:0' shape=(3,) dtype=float32_ref>,
 <tf.Variable 'Variable_11:0' shape=(2,) dtype=complex128_ref>)
#2阶张量
hello = tf.Variable([["Hello"],["World"]],tf.string)
numbers1 = tf.Variable([[1],[2]],tf.int16)
float_number1 = tf.Variable([[1.1],[2.2]],tf.float64)

(<tf.Variable 'Variable_12:0' shape=(2, 1) dtype=string_ref>,
 <tf.Variable 'Variable_13:0' shape=(2, 1) dtype=int32_ref>,
 <tf.Variable 'Variable_14:0' shape=(2, 1) dtype=float32_ref>)
#4阶
my_image = tf.zeros([10,200,200,3])

<tf.Tensor 'zeros:0' shape=(10, 200, 200, 3) dtype=float32>

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值