Python Forum

Full Version: when this error rise?index 28 is out of bounds for axis 0 with size 13
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi
this programm is the heat transfer module but in indexing i have problem this programm working on this way that i should know wher is this element that i select then i should make a Decision to how to fill it at last this array be a the system of equations and solve it.
import numpy as np
h=500+29/2
hg=np.zeros([13,29])
def on_line(i,j):
    if (i==0 and j in range(1,12)) :
        return 'bil'
    elif (i==28 and j in range(1,12)):
        return 'bir'
    elif (j==12 and i in range(1,29)):
        return 'bid'
    elif (i==0 and j==12):
        return 'cil'
    elif (i==28 and j==12):
        return 'cir'
    elif (i==0 and j==0):
        return 'ccvl'
    elif (i==28 and j==0):
        return 'ccvr'
    elif (i in range(1,9) and j==0) or (i in range(20,28) and j==0):
        return 'bcv'
    elif (i in range(10,19)and j==0):
        return 'bcvge'
    elif (i==9 and j==0)or(i==19 and j==0):
        return 'ccvgecd'
    elif (i==9 and j==4 ):
        return 'ccdgel'
    elif (i==28 and j==0):
        return 'ccdgel'
    elif (i==9 and j in range(1,5)):
        return 'cbl'
    elif (j==4 and i in range(10,19)):
        return 'cbd'
    elif (i==19 and j in range(1,5)):
        return 'cbr'
    elif (i in range(10,19)and j in range(1,4)):
        return 'c'
    else:
        return 'bo'
for i in range(29):
    for j in range(13):
        x=on_line(i,j)
        if x=='bil':
            hg[i][j]=(hg[i,j+1]+hg[i,j-1]+2*hg[i+1,j])/4
        if x=='cil':
            hg[i][j]=hg[i][j-1]+hg[i+1][j]
        if x=='bir':
            hg[i][j]=(hg[i][j+1]+hg[i][j-1]+2*hg[i-1][j])/4
Here's a simpler example:
import numpy as np
hg=np.zeros([13,29])
for i in range(29):
    for j in range(13):
        hg[i][j] = 1*13+j
Output:
Traceback (most recent call last): File "...", line 5, in <module> hg[i][j] = 1*13+j IndexError: index 13 is out of bounds for axis 0 with size 13
See the problem now? Look at the values for i and the shape of hg.

There may be other problems.