Q:

Find average in a 2D array

I have 2D numpy array, represents x,y and z columns 'in fact they are points for a 3D image', where you can imagine x as an index repeating, y is the height , z is the value that i want to find out the average for, Example:
[[0, 1, 3],
 [0, 1, 4],
 [0, 2, 5],
 [0, 2, 6],
 [0, 3, 7],
 [1, 4, 0],
 [1, 4, 3],
 [1, 4, 1],
 [1, 2, 2],
 [1, 1, 2],
 [1, 5, 1]....]

the Result is like this 'not with the plus sign but with the result of the avg':
[[0, 1, 3+4/2],
 [0, 2, 5+6/2],
 [0, 3, 7],
 [1, 4, 0+3+1/3],
 [1, 2, 2],
 [1, 1, 2],
 [1, 5, 1]....]

the code may appear to be like this if i'am not wrong:
groups = groupby( groupby( data, axis = 1 ), axis = 0 )
for group in groups :
    average = avg( group, axis = 2 )
    final_result.append = [group[0][0], group[0][1], average]

A:

This is pretty naïve but I think it does what you want...
import itertools

# Make groups based on the first two elements.  
groups = itertools.groupby(a, key=lambda x: (x[0], x[1]))

# Iterate over the groups collecting the third elements. 
result = []
for group in groups:
    this_set = []
    print(group)
    for i in group[1]:
        this_set.append(i[2])
    result.append([i[0], i[1], np.mean(this_set)])

Where results is
[[0, 1, 3.5],
 [0, 2, 5.5],
 [0, 3, 7.0],
 [1, 4, 1.3333333333333333],
 [1, 2, 2.0],
 [1, 1, 2.0],
 [1, 5, 1.0]]

