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

# Note: the following code is running on Python3
import numpy as np
a = np.zeros([10]) # It's a one-dimensional array of 10 length.
b = np.zeros([1,10]) # It's a two-dimensional array of 1 sub-arrays, with each sub-array having 10 elements.
c = np.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)
print ('a =', a)
print ('b =', b)
print ('c =\n', 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.