>>> np.reshape(a, (2, 3))
array([[0, 1, 2],
[3, 4, 5]])
>>> np.reshape(np.ravel(a), (2, 3))
array([[0, 1, 2],
[3, 4, 5]])
>>> np.reshape(a, (2, 3), order='F')
array([[0, 4, 3],
[2, 1, 5]])
>>> np.reshape(np.ravel(a, order='F'), (2, 3), order='F')
array([[0, 4, 3],
[2, 1, 5]])
np.reshape(a, (3,-1))
array([[1, 2],
[3, 4],
[5, 6]])
>>> a = np.arange(6).reshape((3, 2))
>>> a
array([[0, 1],
[2, 3],
[4, 5]])
z.reshape(-1,1)
array([[ 1],
[ 2],
[ 3],
[ 4],
[ 5],
[ 6],
[ 7],
[ 8],
[ 9],
[10],
[11],
[12]])
a = np.array([[1,2,3], [4,5,6]])
>>> np.reshape(a, 6)
array([1, 2, 3, 4, 5, 6])
>>> np.reshape(a, 6, order='F')
array([1, 4, 2, 5, 3, 6])
import numpy as geek
array1 = geek.arange(8)
print("Original array :
", array1)
array2 = geek.arange(8).reshape(-1, 1)
print("
array reshaped with 2 rows and 4 columns :
",
array2)
array3 = geek.arange(8).reshape(4, 2)
print("
array reshaped with 2 rows and 4 columns :
",
array3)
array4 = geek.arange(8).reshape(2, 2, 2)
print("
Original array reshaped to 3D :
",
array4)