python - Read and return values from array with conditions -


i trying read array created , return value inside array column , row found in.this have @ moment.

import pandas pd import os import re  dir = os.getcwd() blks = []  files in dir:     f in os.listdir(dir):         if re.search('txt', f):             blks = [each each in os.listdir(dir) if each.endswith('.txt')] print (blks)  z in blks:     df = pd.read_csv(z, sep=r'\s+', names=['x','y','z'])     = []         = df.pivot('y','x','z')     print (a) 

outputs:

x       300.00  300.25  300.50  300.75  301.00  301.25  301.50  301.75   y                                                                         200.00     100     100     100     100     100     100     100     100    200.25     100     100     100     100     110     100     100     100    200.50     100     100     100     100     100     100     100     100 

x columns , y rows, inside array values corresponding there adjacent column , row. can see above there odd 110 value 10 above other values, i'm trying read array , return x (column) , y (row) value value that's 10 difference checking values next it(top,bottom,right,left) calculate difference.

hope can kindly guide me right direction, , beginner tips appreciated.if unclear i'm asking please ask don't have years experience in methodology,i have started python .

you use dataframe.ix loop through values, row row , column column.

oddcoordinates=[]  r in df.shape[0]:    c in df.shape[1]:       if checkdifffromneighbors(df,r,c):          oddcoordinates.append((r,c)) 

the row , column of values different neighbors listed in oddcoordinates.

to check difference between neighbors, loop them , count how many different values there are:

def checkdifffromneighbors(df,r,c):    #counter of how many different    diffcnt = 0    #loop on neighbor rows    dr in [-1,0,1]:       r1 = r+dr       #row should valid number       if r1>=0 , r1<df.shape[0]:          #loop on columns in row          dc in [-1,0,1]:             #either row or column delta should 0, because not allow diagonal             if dr==0 or dc==0:                c1 = c+dc                #check legal column                if c1>=0 , c1<df.shape[1]:                   if df.ix[r,c]!=df.ix[r1,c1]:                      diffcnt += 1     # if diffcnt==1 neighbor (probably) odd 1    # otherwise 1 odd 1     # note more strict , require neighbors different    if diffcnt>1:       return true    else:       return false 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -