13 Python Numpy库的数组转置

14数组的转置

a = np.arange(1, 25).reshape(8, 3)
print(a)

print('transpose 函数进行数组转置, a[i][j] -- a[j][i]')

b = a.transpose()
print(b, b.shape)

#转置也可用T
print(a.T)

c = np.transpose(a)
print(c, c.shape)
print()
print("--"*30)

多维数组转置

a1 = a.reshape(2, 3, 4)
print(a1, a1.shape)
print('对于三维 a[i][j][k] 进行转置 默认的将i和k交换')

b = np.transpose(a1)
print(b, b.shape)

C = np.transpose(a1, (1, 2, 0))
print(c, c.shape)
发布了36 篇原创文章 · 获赞 0 · 访问量 634

猜你喜欢

转载自blog.csdn.net/Corollary/article/details/105377830