The new shape should be compatible with the original shape. If an
integer, then the result will be a 1-D array of that length.
# Note this question doesn't apply to the function version, `np.reshape`
import numpy as np
a = np.arange(12)
b = a.reshape((4,3)) # (4,3) is passed to `newshape`
c = a.reshape(4,3) # Seems like just 4 would be passed to `newshape`
# and 3 would be passed to next parameter, `order`
def f(a, b=1, order='c'):
# (4, 3)
def f(*a, order='c')
With the way that parameters are bound with normal Python methods, it should not work, but the method is not a Python method at all. Numpy is an extension module for CPython, and
numpy.ndarray.reshape is actually implemented in C.
If you look at the implementation, the
order parameter is only ever read as a keyword argument. A positional argument will never be bound to it, unlike with a normal Python method where the second positional argument would be bound to
order. The C code tries to build the value for
newshape from all of the positional arguments.