Issue
I would like to automatically fill (3x3x3) numpy array of zeros with the pattern the looks like this this, it starts with the coordinate (0.0, 0.0, 0.0)
then sequentially and in the order shown starts to increase the z
by the amount of 3.5
and y
by the amount 6.5
and x
by the amount 6.5
in a sequential manner so that the result will be nodes of a lattice in a 3d-space
0.0 6.5 1.0
0.0 6.5 4.5
0.0 6.5 8.0
0.0 13.5 1.0
0.0 13.5 4.5
0.0 13.5 8.0
0.0 21.0 1.0
0.0 21.0 4.5
0.0 21.0 8.0
6.5 6.5 1.0
6.5 6.5 4.5
6.5 6.5 8.0
6.5 13.5 1.0
6.5 13.5 4.5
6.5 13.5 8.0
13.5 21.0 1.0
13.5 21.0 4.5
13.5 21.0 8.0
21.0 6.5 1.0
21.0 6.5 4.5
21.0 6.5 8.0
21.0 13.5 1.0
21.0 13.5 4.5
21.0 13.5 8.0
21.0 21.0 1.0
21.0 21.0 4.5
21.0 21.0 8.0
Solution
I think this does what you want. Use itertools.product to create the Cartesian product of all of your values.
>>> z = list(itertools.product((0.0,6.5,13.5,21.0),(6.5,13.5,21.0),(1,4.5,9.0)))
>>> z = np.array(z)
>>> z
array([[ 0. , 6.5, 1. ],
[ 0. , 6.5, 4.5],
[ 0. , 6.5, 9. ],
[ 0. , 13.5, 1. ],
[ 0. , 13.5, 4.5],
[ 0. , 13.5, 9. ],
[ 0. , 21. , 1. ],
[ 0. , 21. , 4.5],
[ 0. , 21. , 9. ],
[ 6.5, 6.5, 1. ],
[ 6.5, 6.5, 4.5],
[ 6.5, 6.5, 9. ],
[ 6.5, 13.5, 1. ],
[ 6.5, 13.5, 4.5],
[ 6.5, 13.5, 9. ],
[ 6.5, 21. , 1. ],
[ 6.5, 21. , 4.5],
[ 6.5, 21. , 9. ],
[13.5, 6.5, 1. ],
[13.5, 6.5, 4.5],
[13.5, 6.5, 9. ],
[13.5, 13.5, 1. ],
[13.5, 13.5, 4.5],
[13.5, 13.5, 9. ],
[13.5, 21. , 1. ],
[13.5, 21. , 4.5],
[13.5, 21. , 9. ],
[21. , 6.5, 1. ],
[21. , 6.5, 4.5],
[21. , 6.5, 9. ],
[21. , 13.5, 1. ],
[21. , 13.5, 4.5],
[21. , 13.5, 9. ],
[21. , 21. , 1. ],
[21. , 21. , 4.5],
[21. , 21. , 9. ]])
>>>
Answered By - Tim Roberts
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.