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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:51:50+00:00 2026-05-31T22:51:50+00:00

I am new to using numpy and one thing that I really don’t understand

  • 0

I am new to using numpy and one thing that I really don’t understand is indexing arrays.

In the tentative tutorial there is this example:

>>> a = arange(12).reshape(3,4)
>>> b1 = array([False,True,True])             # first dim selection
>>> b2 = array([True,False,True,False])       # second dim selection
>>>
>>> a[b1,b2]                                  # a weird thing to do
array([ 4, 10])

I have no idea why it does that last thing. Can anyone explain that to me?

Thanks!

  • 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-31T22:51:51+00:00Added an answer on May 31, 2026 at 10:51 pm

    Your array consists of:

    0  1  2  3
    4  5  6  7
    8  9 10 11
    

    One way of indexing it would be using a list of integers, specifying which rows/columns to include:

    >>> i1 = [1,2]
    >>> i2 = [0,2]
    >>> a[i1,i2]
    array([ 4, 10])
    

    Meaning: row 1 column 0, row 2 column 2

    When you’re using boolean indices, you’re telling which rows/columns to include and which ones not to:

    >>> b1 = [False,True,True]       # 0:no,  1:yes, 2:yes       ==> [1,2]
    >>> b2 = [True,False,True,False] # 0:yes, 1:no,  2:yes, 3:no ==> [0,2]
    

    As you can see, this is equivalent to the i1 and i2 shown above. Hence, a[b1,b2] will have the same result.

    Note also that the operation above is only possible because both b1 and b2 have the same number of True values (so, they represent two arrays of the same length when expressed in the integer form).

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

Sidebar

Related Questions

Audio processing is pretty new for me. And currently using Python Numpy for processing
I realize that there is a griddata for NumPy via Matplotlib , but is
I want to mention that I'm new using sql developer and I'm trying to
I generate a list of one dimensional numpy arrays in a loop and later
I am new to using the numpy class and I am having problems with
I still very new using Subversion. Is it possible to have a working copy
New at using admob within Android. Is it possible to show ads with certain
when using new Date,I get something like follows: Fri May 29 2009 22:39:02 GMT+0800
I'm using new style classes in Python 2.6 and am having trouble with __getattr__
Very new to using Raphael.js I'm looking at the tutorials and I am able

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.