Skip to content
Discussion options

You must be logged in to vote

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. 🙂

import torch
import numpy as np
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.empty((1), dtype=object)
b[:] = [a]
print(b)
print(f"Type: {type(b[0])}")

Output:

[Data(x=[10, 1], edge_index=[2, 20])]
Type: <class 'torch_geometric.data.data.Data'>

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@rusty1s
Comment options

@jagandecapri
Comment options

Answer selected by jagandecapri
@rusty1s
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants