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

Joined
Apr 7, 2022
Messages
14
Reaction score
0
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:
return from np.array.png



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

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
 
Joined
May 11, 2022
Messages
60
Reaction score
6
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.
 
Joined
Apr 7, 2022
Messages
14
Reaction score
0
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top