# – What is the difference among tf.zeros([n]), tf.zeros([1,n]) and tf.zeros([n,1])?

# Note: the following code is running on Python3
import tensorflow as tf
a = tf.Variable(tf.zeros([10])) # It's a one-dimensional array of 10 length.
b = tf.Variable(tf.zeros([1,10])) # It's a two-dimensional array of 1 sub-array, with each sub-array having 10 elements.
c = tf.Variable(tf.zeros([10,1])) # It's a two-dimensional array of 10 sub-arrays, with each sub-array having 1 element.
print ('The shape of a is:', a.shape) # The shape of a is: (10,)
print ('The shape of b is:', b.shape) # The shape of b is: (1, 10)
print ('The shape of c is:', c.shape) # The shape of c is: (10, 1)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print ('a =', sess.run(a))
print ('b =', sess.run(b))
print ('c =', '\n', sess.run(c))
# Results:
# a = [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
# b = [[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
# c =
# [[ 0.]
# [ 0.]
# [ 0.]
# [ 0.]
# [ 0.]
# [ 0.]
# [ 0.]
# [ 0.]
# [ 0.]
# [ 0.]]

## Leave a Reply

## Your email is safe with us.