How to store Data objects in Numpy array without the "conversion" of the Data object to Numpy array? #7626
-
The following code: import torch
from torch_geometric.data import Data
x = torch.randn(10, 1)
edge_index = torch.randint(10, size=(2, 20))
a = Data(x=x, edge_index=edge_index)
b = np.array([a], dtype=object)
print(b)
print(f"Type: {type(b[0])}") Gives the following output:
The Data object seems to be "converted" to a Numpy array too. I would like to store the Data object as it is in the Numpy array without conversion. Is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I think I fixed this in #7629 :) |
Beta Was this translation helpful? Give feedback.
-
Hi @rusty1s , Are the fixes in the master branch? I tried installing the package using pip install git+https://github.com/pyg-team/pytorch_geometric.git and executed the code that I stated previously. The Data object still seems to be "converted" to a Numpy array. |
Beta Was this translation helpful? Give feedback.
Noted. I found a workaround following https://stackoverflow.com/questions/43722023/can-i-prevent-numpy-array-from-casting-the-elements-as-numpy-arrays to allocate an empty Numpy array and then populating it with the Data object which doesn't convert the Data object to Numpy array. Sample code as below. Hope it helps someone. 🙂
Output: