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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:35:36+00:00 2026-06-04T04:35:36+00:00

I am new to numpy and am trying to find a Pythonic :) way

  • 0

I am new to numpy and am trying to find a Pythonic 🙂 way to generate a regular 3D grid of points.

With numpy, the ndindex function almost does what I want, but I gather that it only works with integers.

import numpy as np
ind=np.ndindex(2,2,1)
for i in ind:
    print(i)


>>>(0, 0, 0)
(0, 1, 0)
(1, 0, 0)
(1, 1, 0)

I basically want the same thing but using floats to define the values.

I define the dimensions of a box and the number of x, z, and z subdivisions.

Let’s start by creating the x, y, and z dimension linear spaces.

import numpy as np
corner1 = [0.0, 0.0, 0.0]
corner2 = [1.0, 1.0, 1.0]

nx, ny, nz = 5, 3, 7

xspace = np.linspace(corner1[0], corner2[0], nx)
yspace = np.linspace(corner1[1], corner2[1], ny)
zspace = np.linspace(corner1[2], corner2[2], nz)

Now, how should I combine these to give me an array of all the points in my grid?
Thank you for your time!

  • 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-04T04:35:36+00:00Added an answer on June 4, 2026 at 4:35 am

    I find your question a bit confusing, because ndindex returns a generator, but you seem to be asking for an n-dimensional array. A generator is quite easy:

    >>> list(numpy.broadcast(*numpy.ix_(x, y, z)))
    [(0.0, 0.0, 0.0),
     (0.0, 0.0, 1.0),
     (0.0, 0.5, 0.0),
     (0.0, 0.5, 1.0),
     (0.0, 1.0, 0.0),
     (0.0, 1.0, 1.0),
     (1.0, 0.0, 0.0),
     (1.0, 0.0, 1.0),
     (1.0, 0.5, 0.0),
     (1.0, 0.5, 1.0),
     (1.0, 1.0, 0.0),
     (1.0, 1.0, 1.0)]
    

    To pack it into an array, you could create an array and reshape it, remembering that the value triplet is its own dimension (hence the extra 3 at the end).

    >>> numpy.array(list(numpy.broadcast(*numpy.ix_(x, y, z)))).reshape((2, 3, 2, 3))
    array([[[[ 0. ,  0. ,  0. ],
             [ 0. ,  0. ,  1. ]],
    
            [[ 0. ,  0.5,  0. ],
             [ 0. ,  0.5,  1. ]],
    
            [[ 0. ,  1. ,  0. ],
             [ 0. ,  1. ,  1. ]]],
    
    
           [[[ 1. ,  0. ,  0. ],
             [ 1. ,  0. ,  1. ]],
    
            [[ 1. ,  0.5,  0. ],
             [ 1. ,  0.5,  1. ]],
    
            [[ 1. ,  1. ,  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 am new to Numpy and trying to search for a function to list
I have a 2d array in numpy where I want to insert a new
I am trying to find how to apply two functions to a numpy array
I am new of python embedding. I am trying to embed python + numpy
I am new to using numpy and one thing that I really don't understand
I am new to Python and Numpy, and I am facing a problem, that
New Question I am looking for a way in Javascript to get the parent
New to all this so forgive my ignorance. I am trying to figure out
numpy has a function to set the specified elements to be some value a=numpy.zeros(10)
I have come across the numpy.apply_along_axis function in some code. And I don't understand

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.