标签:range numpy import pos div 交换 数组 默认 bsp
1 #导入numpy模块 2 import numpy as np 3 a = np.arange(1,25).reshape(8,3) 4 print(a) 5 print(‘transpose函数进行数组转置a[i][j]---a[j][i]‘) 6 b = a.transpose() 7 print(b,b.shape) 8 9 #可以使用.T 10 print(a.T) 11 12 #numpy中transpose() 13 c = np.transpose(a) 14 print(c,c.shape) 15 16 #多维数组进行转置 17 a = a.reshape(2,3,4) 18 print(a,a.shape) 19 print(‘对于三维a[i][j][k]进行转置 默认的将i和k交换‘) 20 b = np.transpose(a) 21 print(b,b.shape) 22 #指定维度转置:(2,3,4)---->(3,4,2) 23 c = np.transpose(a,(1,2,0)) 24 print(c,c.shape)
1 [[ 1 2 3] 2 [ 4 5 6] 3 [ 7 8 9] 4 [10 11 12] 5 [13 14 15] 6 [16 17 18] 7 [19 20 21] 8 [22 23 24]] 9 transpose函数进行数组转置a[i][j]---a[j][i] 10 [[ 1 4 7 10 13 16 19 22] 11 [ 2 5 8 11 14 17 20 23] 12 [ 3 6 9 12 15 18 21 24]] (3, 8) 13 [[ 1 4 7 10 13 16 19 22] 14 [ 2 5 8 11 14 17 20 23] 15 [ 3 6 9 12 15 18 21 24]] 16 [[ 1 4 7 10 13 16 19 22] 17 [ 2 5 8 11 14 17 20 23] 18 [ 3 6 9 12 15 18 21 24]] (3, 8) 19 [[[ 1 2 3 4] 20 [ 5 6 7 8] 21 [ 9 10 11 12]] 22 23 [[13 14 15 16] 24 [17 18 19 20] 25 [21 22 23 24]]] (2, 3, 4) 26 对于三维a[i][j][k]进行转置 默认的将i和k交换 27 [[[ 1 13] 28 [ 5 17] 29 [ 9 21]] 30 31 [[ 2 14] 32 [ 6 18] 33 [10 22]] 34 35 [[ 3 15] 36 [ 7 19] 37 [11 23]] 38 39 [[ 4 16] 40 [ 8 20] 41 [12 24]]] (4, 3, 2) 42 [[[ 1 13] 43 [ 2 14] 44 [ 3 15] 45 [ 4 16]] 46 47 [[ 5 17] 48 [ 6 18] 49 [ 7 19] 50 [ 8 20]] 51 52 [[ 9 21] 53 [10 22] 54 [11 23] 55 [12 24]]] (3, 4, 2)
标签:range numpy import pos div 交换 数组 默认 bsp
原文地址:https://www.cnblogs.com/monsterhy123/p/12636292.html