Python represents the Matrix Method Analysis, python represents the Matrix
This example describes how to use Python to represent a matrix. We will share this with you for your reference. The details are as follows:
In C language, it indicates a matrix of "Three integer rows and four columns". It can be declared as follows: int a [3] [4]; in python, the variable int cannot be declared, 2. dimensions cannot be listed. You can use the list to enclose the list. For example:
Indicates a matrix, which can be as follows:
Count = 1a = [] for I in range (0, 3): tmp = [] for j in range (0, 3): tmp. append (count) count + = 1. append (tmp) print
Result:
[1, 2, 3], [4, 5, 6], [7, 8, 9]
Note that initialization (when all values are 0) is incorrect !!
Tmp = [] for j in range (0, 3): tmp. append (0) a = [] for I in range (0, 3):. append (tmp) print
Result:
[[0, 0, 0], [0, 0, 0], [0, 0, 0]
Cause: the tmp in this list is the same. If any row is changed, other rows will be changed. Please pay attention to it !!, The following are correct:
A = [] for I in range (0, 3): tmp = [] for j in range (0, 3): tmp. append (0). append (tmp) print