[Python] Find the transposed matrix in a comprehension

About transpose matrix

A = [
    [a1_1, a1_2, ..., a1_W],
    [a2_1, a2_2, ..., a2_W],
       :     :    :     :
    [aH_1, aH_2, ..., aH_W]
]

Matrix A like the one above

At = [
    [a1_1, a2_1, ..., aH_1],
    [a1_2, a2_2, ..., aH_2],
       :     :    :     :
    [a1_W, a2_W, ..., aH_W]
]

It refers to a matrix transformed like At above.

Implementation

displace.py


A = [
    [1, 2], 
    [3, 4], 
    [5, 6]
]

H = 3
W = 2

At = [[A[i][j] for i in range(H)] for j in range(W)]

print(*A, sep="\n")
print("")
print(*At, sep="\n")

Execution result

 > displace.py
[1, 2]
[3, 4]
[5, 6]

[1, 3, 5]
[2, 4, 6]

success.

Recommended Posts

[Python] Find the transposed matrix in a comprehension
Find the eigenvalues of a real symmetric matrix in Python
Transposed matrix in Python standard
Find the Hermitian matrix and its eigenvalues in Python
Draw a scatterplot matrix in python
Find out the apparent width of a string in python
Write the test in a python docstring
Run the Python interpreter in a script
Find and check inverse matrix in Python
Find the rank of a matrix in the XOR world (rank of a matrix on F2)
Find the maximum Python
[Python] Get the files in a folder with Python
Get the caller of a function in Python
Make a copy of the list in Python
Find the number of days in a month
Find the divisor of the value entered in python
List find in Python
Output in the form of a python array
python xlwings: Find the cell in the last row
Check if the string is a number in python
Find the part that is 575 from Wikipedia in Python
Write a log-scale histogram on the x-axis in python
A reminder about the implementation of recommendations in Python
What does the last () in a function mean in Python?
Take a screenshot in Python
Create a dictionary in Python
Download the file in Python
Make a bookmarklet in Python
Draw a heart in Python
Let's find pi in Python
Find the maximum python (improved)
How to find the first element that matches your criteria in a Python list
Create a local scope in Python without polluting the namespace
How to use the __call__ method in a Python class
Change the standard output destination to a file in Python
Write a python program to find the editing distance [python] [Levenshtein distance]
Python --Find out number of groups in the regex expression
[Note] Import of a file in the parent directory in Python
How to get the last (last) value in a list in Python
Visualize the correlation matrix by principal component analysis in Python
Get the index of each element of the confusion matrix in Python
Python --Read data from a numeric data file to find the covariance matrix, eigenvalues, and eigenvectors
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
"A book to train programming skills to fight in the world" Python code answer example --1.8 "0" matrix
Write a binary search in Python
Getting the arXiv API in Python
Hit a command in Python (Windows)
Python in the browser: Brython's recommendation
Save the binary file in Python
Create a DI Container in Python
Get the desktop path in Python
ABC166 in Python A ~ C problem
Get the script path in Python
In the python command python points to python3.8
Implement the Singleton pattern in Python
Create a binary file in Python
Find the Levenshtein Distance with python
[Python] Make the function a lambda function
Solve ABC036 A ~ C in Python
Write a pie chart in Python
Write a vim plugin in Python