
(1) numpy.reshape

a = np.arange(6)
b = np.reshape(a, (2,3))
print("original ndarray: \n", a)
print("reshaped ndarray: \n", b)
'''
original ndarray:
[0 1 2 3 4 5]
reshaped ndarray:
[[0 1 2]
[3 4 5]]
'''

a = np.arange(24)
b = np.reshape(a, (2,3,4))
print("original ndarray: \n", a)
print("reshaped ndarray: \n", b)
'''
original ndarray:
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]
reshaped ndarray:
[[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
[[12 13 14 15]
[16 17 18 19]
[20 21 22 23]]]
'''

(2) ndarray.reshape

import numpy as np
a = np.arange(6)
b = np.reshape(a, (2,3))
print("original ndarray: \n", a)
print("reshaped ndarray: \n", b)
'''
original ndarray:
[0 1 2 3 4 5]
reshaped ndarray:
[[0 1 2]
[3 4 5]]
'''
a = np.arange(24)
b = np.reshape(a, (2,3,4))
print("original ndarray: \n", a)
print("reshaped ndarray: \n", b)
'''
original ndarray:
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]
reshaped ndarray:
[[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
[[12 13 14 15]
[16 17 18 19]
[20 21 22 23]]]
'''
# ndarray.reshape
a = np.arange(6)
b = a.reshape((2,3))
print("original ndarray: \n", a)
print("reshaped ndarray: \n", b, '\n')
b = a.reshape((2,3,4))
print("original ndarray: \n", a)
print("reshaped ndarray: \n", b, '\n')
# np.reshape and ndarray.reshape
a = np.random.randint(0, 100, (100,)) # 20명의 학생과 5개의 과목점수
print(a.reshape((20,5)).mean(axis = 0).max())
print(np.max(np.mean(np.reshape(a,(20,5)), axis = 0)))