如何在Python中转置2 x 2矩阵 [英] How to transpose a 2 x 2 matrice in Python
本文介绍了如何在Python中转置2 x 2矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Python的新功能。我试图找到一种方法来返回2 x 2矩阵的转置副本而不使用Numpy。感谢您的耐心和分享知识的意愿。这是我已经走了多远。
我尝试过:
import math
来自 math import sqrt
import numbers
def T(self):
m = [[m [j] [i] j in 范围(len(m))] 在范围内(len(m [ 0 ]))
print ( n \)
for rez中的行:
print (行)
解决方案
什么是print(n\)?
你从哪里得到代码?你明白了吗?
这个m = [范围(len(m))中的j [[m [j] [i]] in in范围(len (m [0]))未正确形成。它应该是嵌套列表理解。正确的形式应该是:
m = [范围(len(m))中的j [[m [j] [i]]范围内的i(len(m) [0]))]建议您访问一些学习Python的教程网站。
参见 5。数据结构 - Python 3.4.7文档 [ ^ ]。
Fairly new at Python. I am trying to find a way to return a transposed copy of a 2 x 2 matrix without using Numpy. I appreciate your patience and willingness to share knowledge. This is how far I have gotten.
What I have tried:
import math
from math import sqrt
import numbers
def T(self):
m = [[m[j][i] for j in range(len(m))] for in in range(len(m[0]))
print("n\")
for row in rez:
print(row)
解决方案
What'sprint("n\")?
Where did you get the code from? Do you understand it at all?
Thism = [[m[j][i] for j in range(len(m))] for in in range(len(m[0]))is not properly formed. It is supposed to be a nested list comprehension. The correct form should be:
m = [[m[j][i] for j in range(len(m))] for i in range(len(m[0]))]Suggest you visit some tutorial sites on learning Python.
See 5. Data Structures — Python 3.4.7 documentation[^].
这篇关于如何在Python中转置2 x 2矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文