I get the error, list indices must be integers, do not know why?
<pre><code>for i in inpt:
    for j in inpt[i]:
        print j,
</code></pre>

<p>I want to access a 2D array, for each array i in inpt, I want to print each number j in the array i. I do not have any formal background in python and also I could not already find a solution on the internet.</p>

<p>Python <code>for</code> loops are <a href="https://en.wikipedia.org/wiki/Foreach_loop" rel="nofollow"><em>foreach</em> loops</a>, in that you get the actual elements from the list and not an index. You are trying to use those elements as indices to <code>inpt</code> again.</p>

<p>Loop over <code>i</code>, not <code>inpt[i]</code>, to get the matrix values:</p>

<pre><code>for i in inpt:
    for j in i:
        print j,
</code></pre>

<p>I'd rename <code>i</code> to <code>row</code> to make this clearer:</p>

<pre><code>for row in inpt:
    for j in row:
        print j,
</code></pre>

python python-2.7