How to put these outputs into 9 by 9 array using Numpy array
<p>sorry if this is a basic question. I am just starting with python and programming.</p>

<p>I want the output from iteration in a 9 by 9 array. For now I just get the output in one column.</p>

<pre><code>for q in range(11,20,1): 
    for x in range(11,20,1):
        if q &lt;= x: 
            V = 3.5*q â 1.5 * x
        elif q &gt; x: 
            V = 3.5*x â 1.5*x
print(V)
</code></pre>

<p>Try doing this but I get error: <strong>IndexError: index 11 is out of bounds for axis 0 with size 9</strong></p>

<pre><code>import numpy as np
V = np.zeros((9,9))

for q in range(11,20,):
    for x in range(11,20):
        if q &lt;= x:
            V[q][x] = 3.5*q - 1.5*x
        elif q &gt; x:
            V[q][x] = 3.5*x - 1.5*x
print(V)
</code></pre>

<p>Thank you for your help.</p>

<p>Your problem is exactly what the error says: you are trying to access index 11 in a an array of size 9 (by 9).</p>

<p><code>for q in range(11,20):</code> is iterating over <code>q = 11, 12, 13,..., 19</code>. 
Then <code>V[q][x]</code> is trying to access element with indexes <code>q</code> and <code>x</code> in <code>V</code>. But <code>V</code> is of size 9x9 which means the only elements you can access are <code>[0,0], [0,1], ..., [0,8], [1,0], ..., [8,8]</code> hence the error: you are trying to acess an element that doesn't exist.</p>

python arrays numpy multidimensional-array