Add elements in a matrix in python
<p>I have this matrix:</p>

<pre><code>mat = [[ 0 for x in range(row)] for y in range(column)]
</code></pre>

<p>I tried to add elements to the matrix:</p>

<pre><code>for x in range(row): # row is 2 
    for y in range(column): # column is 3
        mat[x][y] = int(input("number: "))
</code></pre>

<p>but the shell returns this error:</p>

<pre><code>Traceback (most recent call last):
File "C:\Users\Fr\Desktop\pr.py", line 13, in &lt;module&gt;
mat[x][y] = 12
IndexError: list assignment index out of range
</code></pre>

<p>how do I add elements to a matrix?</p>

<p>I think it should be:</p>

<pre><code>&gt;&gt;&gt; for x in range(column):
...     for y in range(row):
...             mat[x][y] = int("number: ")
...
1
2
3
4
5
6
&gt;&gt;&gt; mat
[[1, 2], [3, 4], [5, 6]]
</code></pre>

python python-3.x matrix