I have two numpy array data
grid_code=[1,5,8,7,8,3,40,20....]
data= Gridcode X Y LINKCODE
1 .. .. 0
1 .. .. 0
8 .. .. 100
8 .. .. 100
10 .. .. 200
10 .. .. 200
8 .. .. 111
8 .. .. 111
I have write code like this
for i in grid_code:
new_list=numpy.where(data[:,0]==i)[0]
mask_list=data[new_list,:]
I want the output like this in separate file :
Grid code x Y
1 .. ..
1 .. ..
Grid code X Y
5 .. ..
5 .. ..
Grid Code X Y ** This is for the one unique link code (eg.for this time 100)
8 .. ..
8 .. ..
Grid Code X Y
7 .. ..
7 .. ..
Grid Code X Y ** this is for other link code ( this time 111)
8 .. ..
8 .. ..
I need to extract data according to the grid code. I face problem when grid code is repeated. When grid code is repeated I need to extract according to the First LINKCODE in the array.
I have tried like this now with this sample data
grid_code=np.array([6,1,9,6,1,6])
data=np.array([[1,50,40,100],
[1,40,20,100],
[6,50,40,5],
[6,50,20,5],
[9,60,90,10],
[9,90,00,10],
[6,100,100,101],
[6,50,90,101],
[6,101,10,101],
[1,11,11,11],
[1,10,10,11],
[6,200,200,102],
[6,200,200,102]])
new=[]
unique=[]
for i in grid_code:
new_list=numpy.where(data[:,0]==i)[0]
mask_list=data[new_list,:]
unique_mask=numpy.unique(mask_list[:,3]).tolist()
if len(unique_mask)>1:
unique.append([i])
new_unique=np.array(unique)
nq=new_unique[np.where(new_unique[:,0]==i)[0],:]
if len(nq)>=1:
b=len(nq)
a=b-1
for j in range(a,b):
p_list=np.where(mask_list[:,3]==unique_mask[j])[0]
n_list=mask_list[p_list,:]
print n_list
else:
print mask_list
Please have a look on this code and suggest if there is any efficient way of getting the same output.