![](/img/trans.png)
[英]How does NumPy's transpose() method permute the axes of an array?
[英]Python's NumPy: Proper use of a tuple of axis numbers to permute the axes of higher dimensional arrays
有沒有人有直觀的方法來查看通過傳遞軸編號的元組來轉置高維數組的方式?
這是一個例子:
arr = np.arange(16).reshape((2, 2, 4))
ARR
> array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7]],
[[ 8, 9, 10, 11],
[12, 13, 14, 15]]])
arr.transpose((1,0,2))
> array([[[ 0, 1, 2, 3],
[ 8, 9, 10, 11]],
[[ 4, 5, 6, 7],
[12, 13, 14, 15]]])
如果arr.transpose((1, 0))
將顯示為“將軸1與軸0進行轉置(即,將軸1與軸0進行轉置”),則arr.transpose((1, 0, 2))
將顯示為...?
元組中的值引用在進行transpose
調用之前的坐標軸,元組中的索引引用在調用之后的坐標軸。
因此x.transpose( (2,1,3,0) )
將導致先前的第三個軸現在是第一個,先前的第二個軸現在是第二個,先前的第四個軸現在是第三個,並且先前的第一個軸現在是第四個,並且持續。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.