0

I need a function that returns the 3D-coordinates of all points on cubic lattice.

If I had for example 5x5x5 lattice with a width of 30 (some unit), then the x values can be 0, 7.5, 15, 22.5, 30. Likewise for y and z. So I make a list with these positions and want to create all the possible position vectors. How can I do this as efficiently as a possible? Obvioulsy I could do something like this:

one_direction = [0, 10, 20, 30, 40] 
positions = []
for i in one_direction:
    for j in one_direction:
        for k in one_direction:
            positions.append(np.array([i, j, k]))

Is there a better way using Numpy?

  • Possible duplicate of [Using numpy to build an array of all combinations of two arrays](https://stackoverflow.com/questions/1208118/using-numpy-to-build-an-array-of-all-combinations-of-two-arrays) Look at second part of the accepted answer using `meshgrid` – HansHirse Oct 25 '19 at 11:35
  • `np.mgrid[:30:5j, :30:5j, :30:5j].reshape(3, -1).T` – jdehesa Oct 25 '19 at 11:40

0 Answers0