官网定义的结构为:
tf.zeros(
shape,
dtype=tf.float32,
name=None
)
- 1
- 2
- 3
- 4
- 5
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.]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
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.]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
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.]]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8