Create Matrix indexing with array

时间:2015-11-12 11:04:05

标签: python arrays indexing

I have the following problem:

 i  j  x  y
-1 -1 -1 -1 
-1  0 -1  0
-1  1 -1  1
 0 -1  0 -1 
 0  0  0  0 
 0  1  0  1
 .
 . 
 . 
 1  1  1  1

I am trying to arrange an array that has the exact form (the i j give the grid postion xy the coordinates at that position)

Here is what I tried:

SIZE=input("Enter Size of Grid: ")

**def Grid():**
size=SIZE
i=[]
j=[]
k=size
n=size
m=size

while m in range(-size,size+1):
    j0=int(k)
    j=np.append(j,j0)
    i0=int(n)
    i=np.append(i,i0)
    if k == -size:
        n=n-1
    k=k-1
    m=m-1



i=i*-1
j=j*-1

print("j is: ",j)
print("i is: ",i)    

Grid()

Response is:

Enter Size of Grid: 5
j is:  [-5. -4. -3. -2. -1. -0.  1.  2.  3.  4.  5.]
i is:  [-5. -5. -5. -5. -5. -5. -5. -5. -5. -5. -5.]

But I simply havent found a way to repeat this for i=-4-4-4-4-4-4-4....:(

0 个答案:

没有答案