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 6107297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:10:24+00:00 2026-05-23T14:10:24+00:00

I have two numpy arrays: a and b . I want to select all

  • 0

I have two numpy arrays: a and b. I want to select all of the indices where a == 1 and b == 0.

That is, if I have the following arrays:

a = [0, 1, 3, 5, 1, 1, 2]

b = [1, 0, 2, 5, 3, 0, 6]

I would like to get the following indices back:

[1, 5]

How should I do this in numpy? I have tried using the following (suggested by a quick reference guide showing differences between numpy, matlab and IDL):

(a == 1 and b == 0).nonzero()

But that gives an error about truth values being ambiguous.

Any ideas?

  • 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-23T14:10:24+00:00Added an answer on May 23, 2026 at 2:10 pm
    In []: from numpy import array, logical_and
    In []: a= array([0, 1, 3, 5, 1, 1, 2])
    In []: b= array([1, 0, 2, 5, 3, 0, 6])
    In []: logical_and(a== 1, b== 0).nonzero()[0]
    Out[]: array([1, 5])
    

    Obviously this will work as well:

    In []: ((a== 1)& (b== 0)).nonzero()[0]
    Out[]: array([1, 5])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two numpy arrays that are OpenCV convex hulls and I want to
I have hundreds of thousands of NumPy boolean arrays that I would like to
Suppose that I have two numpy arrays of the form x = [[1,2] [2,4]
I have two arrays of x - y coordinates, and I would like to
I have two Numpy record arrays that have exactly the same fields. What is
I have a numpy array that contains some image data. I would like to
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two equal-length 1D numpy arrays, id and data , where id is
The following program loads two images with PyGame, converts them to Numpy arrays, and
I have two NumPy arrays, e.g.: a = [1,2,3,4,5] and a filter array, e.g.:

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.