【发布时间】:2021-05-03 06:42:12
【问题描述】:
这实际上是一个点云形式的网格网格 (n, 3)。
这段代码做到了,剩下的就是矢量化,我正在努力解决这个问题。
也许这里需要一些跨步技巧+重复?
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
dim_len = 5
x = np.linspace(0., 1., dim_len)
y = np.linspace(0., 1., dim_len)
z = np.linspace(0., 1., dim_len)
n_points = dim_len ** 3
point_cloud = np.zeros((n_points, 3))
# TODO vectorize
point_ind = 0
for i in range(dim_len):
for j in range(dim_len):
for k in range(dim_len):
point_cloud[point_ind, 0] = x[i]
point_cloud[point_ind, 1] = y[j]
point_cloud[point_ind, 2] = z[k]
point_ind += 1
print(point_cloud)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(point_cloud[:, 0], point_cloud[:, 1], point_cloud[:, 2],)
plt.show()
【问题讨论】:
标签: python numpy vectorization