Creating a grid type 3D data array from data points

AI Thread Summary
To create a 3D data array from specified ranges of X, Y, and Z values, a numpy array can be generated using a list comprehension. The example provided shows ranges of X from 0 to 5, Y from 0 to 3, and Z from 0 to 2, resulting in a total of 72 data points. While numpy functions like np.indices, np.mgrid, and np.ogrid offer similar functionalities, they do not produce the exact output required. The recommended approach is to use a list comprehension to construct the array in the desired format. This method effectively combines the values into a 2D numpy array with shape 72 x 3.
Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
I have a 3 data column ##(X, Y, Z)## ranges from ##(min, max)##. For example,

##X = (0, 5)##, ##Y=(0, 3)##, ##Z=(0, 2)##. By using them I need to create a numpy array in the form of

##[(0, 0, 0), (0, 0, 1), (0, 0, 2), (0, 1, 0), (0, 1, 1), (0, 1, 2), (0, 2, 0)...]##

So in total there will be ##6 \times 4 \times 3 = 72## data points.

Is there a simple command to do this ?
 
Technology news on Phys.org
numpy arrays cannot hold tuples

If you want to create a 2D 72 x 3 numpy array similar to that there is no simple function*; this is a typical exercise for any aspiring coder.

* the np.indices, np.mgrid and np.ogrid functions do something similar, but I don't think there is anything that does exactly this.

Edit: I suppose you could view a list comprehension as a "simple command" (but the word "command" is not appropriate here):
Python:
np.array([[x, y, z] for x in range(6) for y in range(4) for z in range(3)])
 
Last edited:
  • Like
Likes Wrichik Basu
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top