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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:06:13+00:00 2026-06-11T00:06:13+00:00

I found a very similar question to mine, but not exactly the same. This

  • 0

I found a very similar question to mine, but not exactly the same.
This one: here
However in ntimes’s case the size of the array matches the number of the dimensions the tuple is point at.
In my case I have a 4-dimensional array and a 2-dimensional tuple, just like this:

from numpy.random import rand
big_array=rand(3,3,4,5)
tup=(2,2)

I want to use the tuple as an index to the first two dimensions, and manually index the last two. Something like:

big_array[tup,3,2]

However, I obtain a repetition of the first dimension with index=2, along the fourth dimension( since it technically hasn’t been indexed). That is because this indexing is interpreting a double indexing to the first dimension instead of one value for each dimension,

eg. 
| dim 0:(index 2 AND index 2) , dim 1:(index 3), dim 2:(index 2), dim 3:(no index)|
instead of 
|dim 0(index 2), dim 1(index 2), dim 2:(index 3), dim 3:(index 2)|.

How can I ‘unpack’ this tuple then? Any ideas?
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-06-11T00:06:15+00:00Added an answer on June 11, 2026 at 12:06 am

    You can also pass in your first tuple alone to get the slice of interest, then index it seprately:

    from numpy.random import rand
    big_array=rand(3,3,4,5)
    chosen_slice = (2,2)
    
    >>> big_array[ chosen_slice ]
    array([[ 0.96281602,  0.38296561,  0.59362615,  0.74032818,  0.88169483],
           [ 0.54893771,  0.33640089,  0.53352849,  0.75534718,  0.38815883],
           [ 0.85247424,  0.9441886 ,  0.74682007,  0.87371017,  0.68644639],
           [ 0.52858188,  0.74717948,  0.76120181,  0.08314177,  0.99557654]])
    
    >>> chosen_part = (1,1)
    
    >>> big_array[ chosen_slice ][ chosen_part ]
    0.33640088565877657
    

    That may be slightly more readable for some users, but otherwise I’d lean towards mgilson’s solution.

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

Sidebar

Related Questions

I found a question that was very similar to this one, but using features
I found this question , which is very similar to what I want but
Please note: This question is very similar to this one I found on stackoverflow.
I've found this question very similar to my situation, but I don't know basic
I know that this is a repeated question. I have found very similar questions
My problem is very similar to this question , however I am posting a
I tried to find a similar question here, but found something different. I prefer
I have a very similar problem to the one described in this question .
I know there are other questions that are very similar to this, but their
My question is very similar to a number of others I've found on Stack

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.