I ran the following code in order to obtain a 2-by-3 array:
import numpy as np
a = np.arange(6).resize(2,3)
print(a)
However, the output is
None
Why is this? Many thanks
I ran the following code in order to obtain a 2-by-3 array:
import numpy as np
a = np.arange(6).resize(2,3)
print(a)
However, the output is
None
Why is this? Many thanks
What you want to do is
import numpy as np
a = np.arange(6).reshape((2,3))
print(a)
to use resize :
a = np.arange(6)
a = np.resize(a, (2,3))
reshape doesn't change the base content. But resize should return a new array which is with the requested dimension. Is this right? I just wondered why my code doesn't return a new array.ndarray.resize() returns is exactly None. Thank you for your comment.reshape need that the array have the same number of element. With resize, if the new array is larger than the original array, then the new array is filled with repeated copies of a.