Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8951319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:38:08+00:00 2026-06-15T13:38:08+00:00

I have a 2D array in the following form: [[X1, X2, …, XN] [Y1,

  • 0

I have a 2D array in the following form:

[[X1, X2, ..., XN]
[Y1, Y2, ..., YN]]

For each Xi greater than lower_limit_X and less than upper_limit_X, I would like to get the number of Yi‘s that are greater than lower_limit_Y and less than upper_limit_Y.

I hope there is an efficient way of doing this in Numpy apart from indexing one by one.

EDIT:
So I have a 2xN array. The first row has ordered values of N X’s and second row has ordered values of N Y’s. What I would like to get is:

  1. get a the lowest_index and highest_index index of X, that have a value that is greater than lower_limit_X and less than upper_limit_X

  2. then slice the Y array (just one array) in the index range [lowest_index, highest_index]

  3. count the number of elements in my slice, having Yi's that are greater thanlower_limit_Yand less thanupper_limit_Y`.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:38:09+00:00Added an answer on June 15, 2026 at 1:38 pm

    Here are two ways you could do this, the more strait forward way is probably,

    mask = ((lower_x_limit < array[0]) & (array[0] < upper_x_limit) &
            (lower_y_limit < array[1]) & (array[1] < upper_y_limit))
    count = sum(mask)
    

    If your array is very large and both x and y are sorted you could use searchsorted instead,

    start = array[0].searchsorted(lower_x_limit, 'right')
    end = array[0].searchsorted(upper_x_limit, 'left')
    temp = array[1, start:end]
    start = temp.searchsorted(lower_y_limit, 'right')
    end = temp.searchsorted(upper_y_limit, 'left')
    count = end - start
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following search form <?php echo $this->Form->create('Order', array('action' => 'search','type'=>'get'));?> <?php echo
I have the following Symfony2 form: public function buildForm(FormBuilder $builder, array $options) { $builder
I have an array that looks like the following: array = [[1, 5], [4,
I have the following array coming from a form submission: Array ( [id0] =>
I have the following form in cakephp: <div class=quickcontactDisplay> <?php echo $form->create('Enquiry',array('action'=>'add','class'=>'quickcontact')); echo $form->hidden('visitor_id',
I have an array in the following form, Array ( [foo] => Array (
I have a 2d array of the following form: [ [(, (, (, (,
I have a numpy structured array of the following form: x = np.array([(1,2,3)]*2, [('t',
I have the following form that uses a GET to pass parameters to a
I have a form that looks like the following: <input type=text name=item[101][0][date] value=2012 />

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.