码迷,mamicode.com
首页 > 其他好文 > 详细

Transposed Matrix

时间:2014-08-07 18:52:40      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   os   io   strong   for   

Transposed Matrix

In linear algebra, the transpose of a matrix A is another matrix AT (also written A′, Atr,tA or At) created by any one of the following equivalent actions:

  • reflect A over its main diagonal (which runs from top-left to bottom-right) to obtain AT
  • write the rows of A as the columns of AT
  • write the columns of A as the rows of AT

Formally, the ith row, jth column element of AT is the jth row, ith column element of A:

[AT]i j = [A]j i

If A is an m × n matrix then AT is an n × m matrix.

You have been given a matrix as a 2D list with integers. Your task is to return a transposed matrix based on input.

Input: A matrix as a list of lists with integers.

Output: The transposed matrix as a list of lists with integers.

题目大义: 矩阵转置

1 def checkio(data):
2     rel = []
3     tmp = zip(*data)
4 
5     for each in tmp:
6         rel.append(list(each))
7 
8     #replace this for solution
9     return rel

使用map函数一行解决

1 def checkio(data):
2     return map(list, zip(*data))

多加练习才能孰能生巧

Transposed Matrix,布布扣,bubuko.com

Transposed Matrix

标签:style   blog   color   使用   os   io   strong   for   

原文地址:http://www.cnblogs.com/hzhesi/p/3897629.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!