what is the difference b/w
np.zeros(2)
np.zeros(2,)
np.zeros((2))
np.zeros((2,))
Array initialisation
np.zeros(2) : Makes a list with 2 zeros: [0. 0.]
np.zeros(2,): It will give the same result as above and does not change anything.
np.zeros((2)): Also the same. The extra brackets don’t matter.
np.zeros((2,)): (2,) s a tuple with one number (2).
-> The comma is important because it tells Python, “This is a tuple, not just a number.”
-> When you use np.zeros((2,)), you’re saying:
Create an array with the shape (2,)
, which means a 1D array with 2 elements.