2021年3月23日星期二

How to find most repeated element in a column of 2D array in numpy?

I have a big 2D array that consists of repeated values. I want to find the most repeated element in each "column" in the array. How can I do that?

Here is a part of my array:

array([[5.1, 3.5, 1.4, 0.2],          [4.7, 3.2, 1.3, 0.2],          [4.6, 3.1, 1.5, 0.2],         [5. , 3.6, 1.4, 0.2],          [5.4, 3.9, 1.7, 0.4],          [4.6, 3.4, 1.4, 0.3],          [4.4, 2.9, 1.4, 0.2],          [4.9, 3.1, 1.5, 0.1],         [5.1, 3.7, 1.5, 0.2],         [4.8, 3.4, 1.6, 0.2],         [5.1, 3. , 1.4, 0.1],         [4.3, 3. , 1.1, 0.1],         [5.1, 4. , 1.2, 0.2],         [5.1, 3.5, 1.4, 0.3])  

For example, 5.1 is the most frequent item in the first column of this part of the array.

https://stackoverflow.com/questions/66769785/how-to-find-most-repeated-element-in-a-column-of-2d-array-in-numpy March 24, 2021 at 03:10AM

没有评论:

发表评论