空の 100*100 配列があり、この配列内に数千のランダムな位置/座標があると想像することを意図しています。これらの座標のうち、「直線」エッジの 15 ピクセル内にいくつの座標があるかを計算する必要があります。これまでのところ、私はこのコードを持っています...
import random
import pylab
import numpy #all import statements
pylab.close("all")
x = [(random.randint(0,100)) for i in range(3000)] #creating list of x coordinates
y = [(random.randint(0,100)) for j in range(3000)] #creating list of y coordinates
array=zip(x,y) #creating an array by combining the x and y coordinates
#end of part 1a
counter = 0 #start of 1b
for i in range(100):
for j in range(100):
if i<=15 or i>=85:
if array[i][j]>0:
counter=counter+1
elif j<=15 or j>=85:
if array[i][j]>0:
counter=counter+1
print counter,"random locations within 15 pixels of the edges"
コードを修正するにはどうすればよいですか? 現在、「タプルインデックスが範囲外です」というエラーが表示されます。if array[i][j]>0 行を参照していることは知っていますが、何が問題なのかわかりません...