# Is there a way to get a single mode using all the points within a 2D array?

#### JamesCodingForum

Hi Guys,

What I am looking for:
I want to get the single mode from all 90 points. (in this case, it will be a single mode value of 230)

Is there a way to get a mode of all the elements/points within a 2D array?

When I run:
Code:
`` a = np.array(arrOriginalImage01[YPixelsPerStud*(Yi01-1):YPixelsPerStud*Yi01,XPixelsPerStud*(Xi01-1):XPixelsPerStud*Xi01,0])``
I get the following:

My attempt at solution:
Code:
``````from scipy import stats
stats.mode(a)``````
I get:

This gives me 9 modes, one for each column in my array (aka, this is wrong because it is not a single mode based on all 90 points).

Any ideas?
Thanks

#### phillip1882

i don't know anything about the statistics module, but its fairly straight forward to code it.

just loop over the array keeping track of the most common value.

#### JamesCodingForum

Code:
``````        a = np.array(arrOriginalImage01[YPixelsPerStud*(Yi01-1):YPixelsPerStud*Yi01,XPixelsPerStud*(Xi01-1):XPixelsPerStud*Xi01,0])
arrPixelPerStud02[Yi01-1,Xi01-1,0] = np.average(stats.mode(np.reshape(a,YPixelsPerStud*XPixelsPerStud))[0],None)``````

I think I found a solution by using "numpy.Reshape"

I think the numpy.average part of the code is superfluous but i put it in incase there are multiple modes.