python index out of bounds_IndexError: index 1 is out of bounds for axis 0 with size 1 (Python, NumP...

2017-01-30 14:28:07

0

I am using for loops to iterate through the indices in a NumPy zeros array and assign some indices with the value 0.5. At the moment, my code returns the error message:

IndexError: index 1 is out of bounds for axis 0 with size 1

Below is a simplified version of my code which reproduces the error.

import numpy as np

Z = np.zeros((1560, 1560))

linestart = {1: [175], 2: [865]}

noycuts = 2

cutno = int(0)

for i in range(noycuts):

cutno = cutno + 1

xstart = linestart[cutno]

ystart = 0

for j in range(1560):

Z[xstart][ystart] = 0.5

ystart = ystart + 1

I've checked questions from people with the same error code, although these issues seem to stem from how the array was originally called; I don't think this is my problem.

Can anyone see the flaw in my code that is causing the error message?

I hope I have provided enough information.

Thanks in advance.

你可能感兴趣的:(python,index,out,of,bounds)