python - Finding value in matrix from tuple -


i have matrix:

matrix = np.array([[3,3,3,3,3,3,3,3,3,3,3,3],               [3,2,2,2,2,2,0,0,0,0,0,3],               [3,2,2,2,2,0,0,0,0,0,0,3],               [3,2,2,2,0,0,0,0,0,0,0,3],               [3,2,2,0,0,0,0,0,0,0,0,3],               [3,2,0,0,0,0,0,0,0,0,0,3],               [3,0,0,0,0,0,0,0,0,0,1,3],               [3,0,0,0,0,0,0,0,0,1,1,3],               [3,0,0,0,0,0,0,0,1,1,1,3],               [3,0,0,0,0,0,0,1,1,1,1,3],               [3,0,0,0,0,0,1,1,1,1,1,3],               [3,3,3,3,3,3,3,3,3,3,3,3]]) 

and list of lists filled tuples these:

[[(10, 6), (10, 5), (10, 7), (9, 6), (9, 5), (9, 7)], [(9, 7), (9, 6), (9, 8), (8, 7), (8, 6), (8, 8), (10, 7), (10, 6), (10, 8)], [(10, 7), (10, 6), (10, 8), (9, 7), (9, 6), (9, 8)], [(8, 8), (8, 7), (8, 9), (7, 8), (7, 7), (7, 9), (9, 8), (9, 7), (9, 9)], [(9, 8), (9, 7), (9, 9), (8, 8), (8, 7), (8, 9), (10, 8), (10, 7), (10, 9)], [(10, 8), (10, 7), (10, 9), (9, 8), (9, 7), (9, 9)], [(7, 9), (7, 8), (7, 10), (6, 9), (6, 8), (6, 10), (8, 9), (8, 8), (8, 10)], [(8, 9), (8, 8), (8, 10), (7, 9), (7, 8), (7, 10), (9, 9), (9, 8), (9, 10)], [(9, 9), (9, 8), (9, 10), (8, 9), (8, 8), (8, 10), (10, 9), (10, 8), (10, 10)], [(10, 9), (10, 8), (10, 10), (9, 9), (9, 8), (9, 10)], [(6, 10), (6, 9), (5, 10), (5, 9), (7, 10), (7, 9)], [(7, 10), (7, 9), (6, 10), (6, 9), (8, 10), (8, 9)], [(8, 10), (8, 9), (7, 10), (7, 9), (9, 10), (9, 9)], [(9, 10), (9, 9), (8, 10), (8, 9), (10, 10), (10, 9)], [(10, 10), (10, 9), (9, 10), (9, 9)]] 

which number i'm looking , neighboring spaces aren't <10 in y or x, , i'm using function classify them between spaces filled 0s or else , append them list. how correct function classification?

def classify(neighbors,matrix):     x in neighbors:         y = x[0]         z = x[1]         if matrix[y][z] == 0:             step.append(x)         else:             hop.append(x)  print(hop,step) 

import numpy np array import * matrix = np.array([[3,3,3,3,3,3,3,3,3,3,3,3],               [3,2,2,2,2,2,0,0,0,0,0,3],               [3,2,2,2,2,0,0,0,0,0,0,3],               [3,2,2,2,0,0,0,0,0,0,0,3],               [3,2,2,0,0,0,0,0,0,0,0,3],               [3,2,0,0,0,0,0,0,0,0,0,3],               [3,0,0,0,0,0,0,0,0,0,1,3],               [3,0,0,0,0,0,0,0,0,1,1,3],               [3,0,0,0,0,0,0,0,1,1,1,3],               [3,11,11,0,0,0,0,1,1,1,1,3],               [3,12,12,0,0,0,1,1,1,1,1,3],               [3,3,13,3,3,3,3,3,3,3,3,3]])  neighbors = [[(10, 6), (10, 5), (10, 7), (9, 6), (9, 5), (9, 7)],(10, 5),[(9, 7), (9, 6), (9, 8), (8, 7), (8, 6), (8, 8), (10, 7), (10, 6), (10, 8)]] def classify(neighbors,matrix):     hop = []     step = []     x in neighbors:       print x       if isinstance(x,list):         x1 in x:           y = x1[0]           z = x1[1]           if matrix[y][z] == 0:              step.append(x1)           else:             hop.append(x1)       else:         y = x[0]         z = x[1]         if matrix[y][z] == 0:              step.append(x)         else:             hop.append(x)      print "neighbors not having value 0 =" ,hop     print "neighbors having 0 value =" ,step classify(neighbors,matrix) 

output :-

neighbors not having value 0 = [(10, 6), (10, 7), (9, 7), (9, 7), (9, 8), (8, 8), (10, 7), (10, 6), (10, 8)] neighbors having 0 value = [(10, 5), (9, 6), (9, 5), (10, 5), (9, 6), (8, 7), (8, 6)] 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -