我想更改矩阵的轴x和轴。y例如,我想将每个嵌套数组的第一个元素存储在第一行,将每个嵌套数组的第二个元素存储在第二行等...例如:list = [[1,2,3,4,5,6]
[7,8,9,10,11,12]
[13,14,15,16,17,18]
[19,20,21,22,23,24]]我想改成这样:new list = [[1,7,13,19]
[2,8,14,20]
[3,9,15,21]
[4,10,16,22]
[5,11,17,23]
[6,12,18,24]]注意:这不是旋转
1 回答
萧十郎
TA贡献1815条经验 获得超13个赞
使用
numpy.ndarray.T
,这与numpy.transpose
import numpy as np
data = [[1,2,3,4,5,6],
[7,8,9,10,11,12],
[13,14,15,16,17,18],
[19,20,21,22,23,24]]
# convert the list of lists to an array
data = np.array(data)
# transpose the array
data_t = data.T
# print(data_t)
array([[ 1, 7, 13, 19],
[ 2, 8, 14, 20],
[ 3, 9, 15, 21],
[ 4, 10, 16, 22],
[ 5, 11, 17, 23],
[ 6, 12, 18, 24]])
添加回答
举报
0/150
提交
取消