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!