import numpy as np
x = np.array([2, 4, 7, 9, 20])
print('x的形状:', x.shape) # x的形状: (5,)
print('x的值:', x) # x的值: [ 2 4 7 9 20]
x_new1 = x[np.newaxis, :]
# (5,) -----》 (1, 5)
print('x_new1的形状:', x_new1.shape) # x_new1的形状: (1, 5)
print('x_new1的值:', x_new1) # x_new1的值: [[ 2 4 7 9 20]]
x_new2 = x[:, np.newaxis]
# (5,) -----》 (5, 1)
print('x_new2的形状:', x_new2.shape) # x_new2的形状: (5, 1)
print('x_new2的值:', x_new2) #
# x_new2的值: [[ 2]
# [ 4]
# [ 7]
# [ 9]
# [20]]