NumPy 中的 swapaxes函数

首页 / Numpy入门教程 / NumPy 中的 swapaxes函数

此函数互换数组的两个轴,对于1.10之后的NumPy版本,将返回交换数组的视图,该函数采用以下参数。

numpy.swapaxes(arr, axis1, axis2)
Sr.No. Parameter & 描述
1

arr

要交换其轴的输入数组

2

axis1

与第一个轴对应的int

无涯教程网

3

axis2

与第二个轴对应的int

链接:https://www.learnfk.comhttps://www.learnfk.com/numpy/numpy-swapaxes.html

来源:LearnFk无涯教程网

# It creates a 3 dimensional ndarray 
import numpy as np 
a=np.arange(8).reshape(2,2,2) 

print 'The original array:' 
print a 
print '\n'  
# now swap numbers between axis 0 (along depth) and axis 2 (along width) 

print 'The array after applying the swapaxes function:' 
print np.swapaxes(a, 2, 0)

其输出如下-

The original array:
[[[0 1]
 [2 3]]

 [[4 5]
  [6 7]]]

The array after applying the swapaxes function:
[[[0 4]
 [2 6]]
 
 [[1 5]
  [3 7]]]

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

AI技术内参 -〔洪亮劼〕

硅谷产品实战36讲 -〔曲晓音〕

深入剖析Kubernetes -〔张磊〕

白话法律42讲 -〔周甲徳〕

重学前端 -〔程劭非(winter)〕

SRE实战手册 -〔赵成〕

程序员的个人财富课 -〔王喆〕

如何讲好一堂课 -〔薛雨〕

李智慧 · 高并发架构实战课 -〔李智慧〕

好记忆不如烂笔头。留下您的足迹吧 :)