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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:20:14+00:00 2026-05-26T19:20:14+00:00

I have the following 3 x 3 x 3 numpy array called a (the

  • 0

I have the following 3 x 3 x 3 numpy array called a (the comments will make sense after you read the rest of the question):

array([[[8, 1, 0],     # irrelevant 1 (is at position 1 rather than 0)
        [1, 7, 5],     # the 1 on this line is what I am after!
        [1, 4, 9]],    # irrelevant 1 (out of the "cross")

       [[4, 0, 1],     # irrelevant 1 (is at position 2 rather than 0)
        [1, 0, 1],     # I'm only after the first 1 on this line!
        [6, 2, 1]],    # irrelevant 1 (is at position 2 rather than 0)

       [[0, 2, 2],
        [0, 6, 7],
        [3, 4, 9]]])

furthermore I have this list of indexes that refers to the “central cross” of said matrix, called idx

[array([0, 1, 1, 1, 2]), array([1, 0, 1, 2, 1])]

EDIT: I call it “cross” as it marks the central column and row in the following:

>>> a[..., 0]
array([[8, 1, 1],
       [4, 1, 6],
       [0, 0, 3]])

What I would like to obtain is the indexes of all those arrays located at idx whose first value is 1, but I’m struggling in understanding how to use numpy.where() in the right way. Since…

>>> a[..., 0][idx]
array([1, 4, 1, 6, 0])

…I tried…

>>> np.where(a[..., 0][idx] == 1)
(array([0, 2]),)

…but as you can see it returns the index of the sliced array, not of a, while I would like to get:

[array([0, 1]), array([1, 1])]  #as a[0, 1, 0] and a [1, 1, 0] are equal to 1.

Thank you in advance for your help!

PS: In the comments I have been suggested to try to give a broader scenario of applicability. Although it is not what I am using for, I suppose this could be used to process images as many 2D libraries do, with a source layer, a destination layer and a mask (see for example cairo). In this case the mask would be the idx array, and one might imagine working with the R channel of RGB colors (a[..., 0]).

  • 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-26T19:20:15+00:00Added an answer on May 26, 2026 at 7:20 pm

    You can translate the indices back using idx:

    >>> w = np.where(a[..., 0][idx] == 1)[0]
    >>> array(idx).T[w]
    array([[0, 1],
           [1, 1]])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following numpy array: # A B C Y my_arr = np.array([
If I have the following matrix: import numpy ar = numpy.array((('0','1','2','3'), ('1','a','b','b'), ('2','b','c','d')), str)
I have the following array: >>> x = numpy.array([2,4,2,3,1]) >>> x array([2, 4, 2,
I have the following code which first selects elements of a NumPy array with
I have a 2D numpy array. Lets consider the following example [[0,6,89,255,1,6,7] [0,255,89,255,1,1,7] [255,255,255,255,255,255,255]
I have the following array in NumPy: A = array([1, 2, 3]) How can
I have the following range of numpy data (deltas of usec timestamps): array([ 4.312,
I have the following array in Python: points_list = [point0, point1, point2] where each
I have a 2d array in numpy where I want to insert a new
I have a numpy array (we'll call it test) of ~286 x 181 x

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.