Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

python - Int object is not subscriptable problem with array?

Still new to this place and python so if I am doing something wrong, please tell. Have looked at previous questions, none seem to fix it as far as I can tell.

I have written a piece of code to generate an island, and I have written down here all the code in which there could be an error, I think. The code fails at the third to last line. I get the error

if drainsL[j, k + 1] == 1:

TypeError: 'int' object is not subscriptable

What is wrong with it?


Draining=river_generator.setupBools(Vecsize,1,Blended)
Draining,Fills=river_generator.solve_terrain_water(Blended,Vecsize,Vecsize,drainsL= Draining)

Vecsize = 140
Blended can be a random array, it does not matter in this case


def setupBools(size,threshold,terrain):
    boolsL=np.zeros(size*size)
    boolsL = boolsL.reshape(size,size)
    for i in range (0,size):
        for j in range (0,size):
            if terrain[i,j] < threshold:
                boolsL[i,j] = 1
    return boolsL

def solve_terrain_water(terrain, passes, size, drainsL):

    fillL=np.zeros(size*size)
    fillL= fillL.reshape(size,size)

    #for j in range(2, size - 2):
     #   print('j', j)
      #  print(drainsL[j, :])
       # for k in range (2,size-2):
        #    print('k',k+1)
         #   print(drainsL[j,k+1],drainsL[j,k+1].dtype)


    for i in range (1,passes):
        for j in range (1,size-1):
            for k in range (1,size-1):
                min=99999999
                myter=terrain[j,k]
                if drainsL[j, k + 1] == 1:
                    if terrain[j,k+1]+fillL[j, k + 1]<min:
                        min = terrain[j,k+1] + fillL[j, k + 1]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...