I somehow didn't understand the reshape of np. However, when I wrote the code, I somehow understood it, so I wanted to share it for those who want to study intuitively.
np_reshape_.py
#1 row 12 columns
list_1 = [10.0, 14.0, 23.0, 27.0, 37.0, 58.0, 81.0, 82.0, 135.0, 169.0, 344.0, 319.0]
print(list_1)
#[10.0, 14.0, 23.0, 27.0, 37.0, 58.0, 81.0, 82.0, 135.0, 169.0, 344.0, 319.0]
#3 rows 4 columns
list_2 = np.array(list_1).reshape(3, 4)
print(list_2)
"""
[[ 10. 14. 23. 27.]
[ 37. 58. 81. 82.]
[135. 169. 344. 319.]]
"""
#6 rows 2 columns
list_3 = np.array(list_1).reshape(6, 2)
print(list_3)
"""
[[ 10. 14.]
[ 23. 27.]
[ 37. 58.]
[ 81. 82.]
[135. 169.]
[344. 319.]]
"""
#6 rows, 2 columns, 2 columns, coordinate system
list_4 = np.array(list_1).reshape(-1, 2)
print(list_4)
"""
[[ 10. 14.]
[ 23. 27.]
[ 37. 58.]
[ 81. 82.]
[135. 169.]
[344. 319.]]
"""
#6 rows 2 columns
list_5 = np.array(list_1).reshape(6, -1)
print(list_5)
"""
[[ 10. 14.]
[ 23. 27.]
[ 37. 58.]
[ 81. 82.]
[135. 169.]
[344. 319.]]
"""
I intuitively understood how to use -1 of reshape of np.
Recommended Posts