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

  • Home
  • SEARCH
  • 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 6559123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:17:02+00:00 2026-05-25T13:17:02+00:00

Lets say I have an array, ‘foo’, with two columns. Column 0 has values

  • 0

Lets say I have an array, ‘foo’, with two columns. Column 0 has values 1 to 12 indicating months. Column 1 has the corresponding measurement values. If I wanted to create a mask of measurement values from December, January and February (12,1,2) I would suspect that I could:

numpy.where(foo[:,1] in (12, 1, 2), False, True)

But it would appear that my clever ‘in (12, 1, 2)’ doesn’t work as a conditional for where(). Nor does it appear to work as [12, 1, 2], etc…

Is there another clever way to do this? Is there a better way for me to collect all of the (12, 1, 2) measurements into an array? What is the numpy way?

(Reshaping the array is out of the question because there are an irregular number of measurements for each month)

  • 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-05-25T13:17:03+00:00Added an answer on May 25, 2026 at 1:17 pm

    I think the reason the ‘in (12, 1, 2)’ does not work is that the element before the ‘in’ has to be a single element.

    But for this, numpy has the function in1d (documentation) to do a ‘in’ with a numpy array. With your code:

    np.where(np.in1d(foo[:,0], [12, 1, 2]), False, True)
    

    To complete the answer with the comment: in this case using where is redundant, the output of in1d can be used to index foo:

    foo[np.in1d(foo[:,0], [12, 1, 2])]
    

    or for

    foo[~np.in1d(foo[:,0], [12, 1, 2])]
    

    Note: in1d is only available from numpy 1.4 or higher.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have an array which has n dimensions. Now in order to
Lets say I have an array numbers that contains the following values: int numbers
Lets say i have a simple array of x rows and y columns with
I currently have an array of values (business_id's) lets say its Array ( [0]
I have an Array with some String objects lets say months. [October] [May] [July]
Lets say I have string like this: String q = foo (one) bla (two)
Lets say I have the following two PHP arrays that contain integers: $foo =
Lets say I have an array like this: string [] Filelist = ... I
Lets say I have this array, int[] numbers = {1, 3, 4, 9, 2};
Lets say I have an array of length n and I want to pick

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.