1

I have an numpy array of dimension values in this structure:

arr = array([[3067,   78, 3172,  134],
             [3237,   89, 3394,  128],
             [3475,   87, 3743,  141],
             [3763,   86, 3922,  131],
             [3238,  147, 3259,  154]])

which basically stores the location of data located in the screen, where the values represented as: [x_left, y_top, x_right, y_bottom]]

I only need to work on the x_left values, as I am trying to find where on the page I am most likely able to find these objects.

I am aware of scipy.mode, which returns mode values. Is there a way to return multiple modes, say the top 10 mode values in a given numpy column? Better yet, is there a way to use mode so that a mode is within a given range? For example, the lines above have x_left values of 3237 and 3238, which are fairly closely aligned. Is there a way to calculate these two as a single mode value?

1 Answer 1

1

You can convert your numpy array column to a pandas series and use .value_counts()

import pandas as pd
x_left = pd.Series(arr[:,0])
x_left.value_counts()
#3475    1
#3237    1
#3067    1
#3763    1
#3238    1
#dtype: int64

You could also round the values to, for example the nearest 10 integer to group values between ranges

def customRound(x, base=10):
    return base * round(x/base)
x_left_round = x_left.apply(customRound)
x_left_round.value_counts()
#3240    2
#3760    1
#3070    1
#3480    1
#dtype: int64

You can then see that you have two x_left values close to 3240

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.