tensorflow笔记:常用函数

来源:互联网 发布:算法工程师 待遇 编辑:程序博客网 时间:2024/06/05 02:11

常用函数

1、tf.constant

tf.constant(value,dtype=None,shape=None,name=’Const’,verify_shape=False)
作用:创建一个常量tensor
参数:
value: 一个dtype类型(如果指定了)的常量值或list。
  如果value是一个list,len(value)不能够超过shape参数指定的大小(如果已指定);
  要是len(list)小于shape指定的大小,多余的则由list的最后一个元素进行填充。
dtype: 返回tensor的类型
shape: 指定tensor的形状。
name: tensor的名字
verify_shape:是否允许对值的形状进行验证。

import tensorflow as tf#build grapha = tf.constant(2,shape=[2],name='a')b = tf.constant(2,shape=[2,2])c = tf.constant([1,2,3],shape=[6])d = tf.constant([1,2,3],shape=[3,2])#construct sessionsess=tf.Session()#run in sessionprint "a:",aprint "name of a:",a.nameprint sess.run(a)print "b:",bprint "type of b:",type(b)print sess.run(b)print "c:",cprint "type of c:",type(c)print sess.run(c)print "d:",dprint "type of d:",type(d)print sess.run(d)
原创粉丝点击