Closed FabricioArendTorres closed 1 year ago
Ok, I think I figured it out, but I have to admit the named dimensions are a bit weird (and include redundant information?):
from phi.torch.flow import *
import numpy as np
data_x = np.random.rand(10, 2)
density = np.exp(-(data_x**2).sum(-1)).reshape(10, 1)
points = math.tensor(data_x, instance(points=data_x.shape[0]), channel(vector='x,y'))
vals = math.tensor(density, instance(points=data_x.shape[0]), channel(value='density'))
pc = PointCloud(elements=points, values=vals, )
plot(pc)
You can actually leave out the redundant sizes:
data_x = np.random.rand(10, 2)
density = np.exp(-(data_x**2).sum(-1))
points = tensor(data_x, instance('points'), channel(vector='x,y'))
vals = tensor(density, instance(points))
pc = PointCloud(elements=points, values=vals)
plot(pc)
But yeah, converting native arrays adds a bit of declaration to your code. However, everything you do with it afterwards should be shorter than the corresponding NumPy/TF/PyTorch/Jax code.
Hi,
if I have a numpy / torch / tensorflow array that contains n points with dimension dim in the shape of (n, dim), how would I initialize a PointCloud with that? The docs and tutorials are not really helpful for that, but only describe how to generate point clouds directly from phiflow Tensors.