What is the difference between
numpy.zeros(n)
and
numpy.zeros(n,1)
?
The output for the first statement is
[0 0 ..... n times]
whereas the second one is
([0] [0]
.... n rows)
What is the difference between
numpy.zeros(n)
and
numpy.zeros(n,1)
?
The output for the first statement is
[0 0 ..... n times]
whereas the second one is
([0] [0]
.... n rows)
The first argument indicates the shape of the array. A scalar argument implies a "flat" array (vector), whereas a tuple argument is interpreted as the dimensions of a tensor. So if the argument is the tuple (m,n)
, numpy.zeros
will return a matrix with m
rows and n
columns. In your case, it is returning a matrix with n
rows and 1
column.
Although your two cases are equivalent in some sense, linear algebra routines that require a vector as input will likely expect something like the first form.