Junior — Middle
How can a numpy array be organized to store coordinates of points in space in the XYZ system, where each triplet of numbers corresponds to one point?
sobes.tech AI
Answer from AI
To store the coordinates of points in 3D space XYZ in numpy, a two-dimensional array with shape (N, 3) is usually used, where N is the number of points, and 3 represents the X, Y, and Z coordinates of each point.
Example of creating such an array:
import numpy as np
# Create an array of 5 points
points = np.array([
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0],
[10.0, 11.0, 12.0],
[13.0, 14.0, 15.0]
])
print(points.shape) # (5, 3)
print(points[0]) # [1.0, 2.0, 3.0] - first point
This format is convenient for vector operations, filtering, and data transfer to graphical or computational functions.