TensorFlow函数之tf.constant()

tf.constant()可以实现生成一个常量数值。


tf.constant()格式为:

tf.constant(value,dtype,shape,name)

参数说明:

  1. value:常量值
  2. dtype:数据类型
  3. shape:表示生成常量数的维度
  4. name:数据名称

下边生成一个0.1常量大小为2*2的数据:

import tensorflow as tf

v = tf.constant(0.1, dtype=tf.float32, shape=[2, 2], name='v')

sess = tf.Session()
print(sess.run(v))
sess.close()

输出为:

[[0.1 0.1]
 [0.1 0.1]]

猜你喜欢

转载自blog.csdn.net/Sophia_11/article/details/84031708
今日推荐