圆月山庄资源网 Design By www.vgjia.com

如下所示:

#!/usr/bin/env python
#-*- coding: utf-8 -*-
 
"""
[0, 1, 2, 3]
[0, 1, 2, 3]
[0, 1, 2, 3]
[0, 1, 2, 3]
2维数组顺时针90度旋转后结果如下
[0, 0, 0, 0]
[1, 1, 1, 1]
[2, 2, 2, 2]
[3, 3, 3, 3]
[0][1] <==> [1][0]
[0][2] <==> [2][0]
[0][3] <==> [3][0]
[1][2] <==> [2][1]
[1][3] <==> [3][1]
[2][3] <==> [3][2]
"""
 
data=[[i for i in range(4)] for raw in range(4)]
for ele in data:
 print ele
a=len(data)
for i in range(a):#外层循环
 for j in range(i+1,len(data[i])): #内层循环
  #交换数据
  temp=data[i][j]
  data[i][j]=data[j][i]
  data[j][i]=temp
for ele in data:
 print ele

以上这篇python 二维数组90度旋转的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

标签:
python,二维数组,旋转

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com