28 Aug
2010
28 Aug
'10
5:57 a.m.
Hello, In section 5.1 [1] of Python 3 online documentation, you discuss ways to transpose a matrix represented as a nested list. The following example is given: mat = [ ... [1, 2, 3], ... [4, 5, 6], ... [7, 8, 9], ... ] list(zip(*mat)) [(1, 4, 7), (2, 5, 8), (3, 6, 9)] That's correct only if further code ignores the distinction between tuples and lists. In the code as it is, the 'list' part is actually redundant, as zip will return a list anyway. To transpose a matrix using zip, the following seems more accurate: map(list, zip(*m)) Regards, vQ [1] http://docs.python.org/py3k/tutorial/datastructures.html#nested-list-compreh...
4989
Age (days ago)
4989
Last active (days ago)
0 comments
1 participants
participants (1)
-
Wacek Kusnierczyk