您的位置:首页 > 其它

Tensorflow | Constants |常用函数介绍

2017-03-05 16:58 363 查看
根据官网的帮助文档,介绍Constants类型的函数,方便自己学习和查看。若是有幸帮到别的朋友,深感荣幸。

常值张量

tf.zeros

产生元素0

格式:tf.zeros(shape, dtype=tf.float32, name=None)

shape表示维数,dtype定义类型,name定义名称

例子:

tf.zeros(shape=[3, 4], dtype=int32) ==> [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]


tf.zeros_like

产生类似与tensor的全0张量

格式:tf.zeros_like(tensor, dtype=None, name=None)

tensor是一个张量,dtype定义类型,name定义名称

例子:

# 'tensor' is [[1, 2, 3], [4, 5, 6]]
tf.zeros_like(tensor) ==> [[0, 0, 0], [0, 0, 0]]


tf.ones

产生全是1的张量

格式:tf.ones(shape, dtype=tf.float32, name=None)

shape定义维度,dtype定义类型,name定义名称

例子:

tf.ones(shape=[2, 3], dtype=int32) ==> [[1, 1, 1], [1, 1, 1]]


tf.ones_like

产生类似与张量tensor的全1张量

格式:tf.ones_like(tensor, dtype=None, name=None)

tensor是一个张量,dtype定义类型,name定义名称

例子:

# 'tensor' is [[1, 2, 3], [4, 5, 6]]
tf.ones_like(tensor) ==> [[1, 1, 1], [1, 1, 1]]


tf.fill

填充,用value来填充shape=dims的张量

格式:tf.fill(dims,value,name=None)

dims定义维度,value给定数值,name定义名称

例子:

# output tensor shape needs to be [2, 3]
# so 'dims' is [2, 3]
tf.fill(dims, 9) ==> [[9, 9, 9]
[9, 9, 9]]


tf.constant

定义常数张量

格式:tf.constant(value,dtype=None,shape=None,name=’Const’)

value给定的值,dtype定义类型,shape定义维度,name定义名称

例子:

# Constant 1-D Tensor populated with value list.
tensor = tf.constant(value=[1, 2, 3, 4, 5, 6, 7]) => [1 2 3 4 5 6 7]

# Constant 2-D tensor populated with scalar value -1.
tensor = tf.constant(value=-1.0, shape=[2, 3]) => [[-1. -1. -1.]
[-1. -1. -1.]]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  tensorflow Constants