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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:17:44+00:00 2026-06-13T02:17:44+00:00

Say I create an array of arbitrary dimension (n). #assign the dimension >>> n=22

  • 0

Say I create an array of arbitrary dimension (n).

#assign the dimension

>>> n=22

#create the numpy array

>>> TheArray=zeros([2]*n)

>>> shape(TheArray)

(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)

Have some code (skipped in this example) to populate the values of the array.

Now, try to access some values of the array

>>> TheArray[0:2,0:2,0:2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

array([[[ 0.,  0.],
        [ 0.,  0.]],

       [[ 0.,  0.],
        [ 0.,  0.]]])

How to make the 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 part of the syntax generalized to n?

  • 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-13T02:17:45+00:00Added an answer on June 13, 2026 at 2:17 am

    One way would be to use numpy.s_:

    In [55]: m = arange(2**6).reshape([2]*6)
    
    In [56]: m.shape
    Out[56]: (2, 2, 2, 2, 2, 2)
    
    In [57]: m[:2,:2,:2,0,0,0]
    Out[57]: 
    array([[[ 0,  8],
            [16, 24]],
    
           [[32, 40],
            [48, 56]]])
    
    In [58]: m[s_[:2, :2, :2] + (0,)*(n-3)]
    Out[58]: 
    array([[[ 0,  8],
            [16, 24]],
    
           [[32, 40],
            [48, 56]]])
    

    And I guess you could get rid of the hardcoded -3..

    In [69]: m[(s_[:2, :2, :2] + (0,)*m.ndim)[:m.ndim]]
    Out[69]: 
    array([[[ 0,  8],
            [16, 24]],
    
           [[32, 40],
            [48, 56]]])
    

    but to be honest, I’d probably just wrap this up in a function if I needed it.

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

Sidebar

Related Questions

Let's say I create an instance of a class and want to assign some
Say I wanna create an array of images and i used this: NSMutableArray *images
Let's say that I create a vector/array in Scheme: (let* ((x #(1 2 3)))
Let's say I create a jagged 2d array like so: public static char[,] phoneLetterMapping
Say i have those 3 arrays : Product(milk,candy,chocolate) Colors(white,red,black) Rating(8,7,9) How to create a
Say I create some object class like so public class thing { private String
Say I wanted to create an array (NOT list) of 1,000,000 twos in python,
Say you have class Block Class Block : NSObject Now, you want to create
Say I want to create an array of pixel values to pass into the
Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString

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.