x = np.array([1, 2, 3])
print(x)
x.reshape((1, 3))
My question is: why are there two parenthesis in ((1, 3))? When I write it like this:
x.reshape(1, 3)
...the answer comes out the same. So why the two parenthesis?
x = np.array([1, 2, 3])
print(x)
x.reshape((1, 3))
My question is: why are there two parenthesis in ((1, 3))? When I write it like this:
x.reshape(1, 3)
...the answer comes out the same. So why the two parenthesis?
According to the docs:
Unlike the free function numpy.reshape, this method on ndarray allows the elements of the shape parameter to be passed in as separate arguments.
So it's just a convenience. Almost everywhere else in NumPy, e.g. np.ones((2,3)), it's more usual to pass shapes with the parentheses around the shape tuple. In fact, I can't think of anywhere else!