tf.zeros()的使用

官网定义的结构为:

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

shape代表形状,也就是1纬的还是2纬的还是n纬的数组。
下面看图说话:

1. 一维数组里放一个值

import tensorflow as tf
res = tf.random_uniform((4, 4), -1, 1)
res2 = tf.zeros([1])
with tf.Session() as sess:
    print(sess.run(res2))
#结果为:
[0.]

2. 一维数组里放两个值

import tensorflow as tf
res = tf.random_uniform((4, 4), -1, 1)
res2 = tf.zeros([2])
with tf.Session() as sess:
    print(sess.run(res2))
#结果为:
[0. 0.]

3. 二维数组

import tensorflow as tf
res = tf.random_uniform((4, 4), -1, 1)
res2 = tf.zeros([2, 4])
with tf.Session() as sess:
    print(sess.run(res2))
#结果为:
[[0. 0. 0. 0.]
 [0. 0. 0. 0.]]

猜你喜欢

转载自blog.csdn.net/yexudengzhidao/article/details/80981494