Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between numpy.zeros(n) and numpy.zeros(n,1) [duplicate]

Tags:

python

numpy

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)

like image 254
Apratim Bhattacharya Avatar asked Oct 22 '25 16:10

Apratim Bhattacharya


1 Answers

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.

like image 184
Gabe Hackebeil Avatar answered Oct 25 '25 04:10

Gabe Hackebeil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!