How to make numpy.ndarray of DGLGraph

Dear forum members,

When I tried making numpy.ndarray of DGL heterographs,
I got error msg below

File "/path/to/dgl/heterograph.py", line 2152, in __getitem__
raise DGLError('Invalid key "{}". Must be one of the edge types.'.format(orig_key))
dgl._ffi.base.DGLError: Invalid key "0". Must be one of the edge types.

Here is my sample code:

import dgl
import torch as th
import numpy as np

u, v = th.tensor([0, 0, 0, 1]), th.tensor([1, 2, 3, 3])
g = dgl.graph((u, v))

gnp = np.array( g )

What is wrong in my code??
Why DGLGraph.getitem is called??

Any help is appreciated.
Thank you.

It’s not allowed to construct a NumPy array of DGLGraphs.

Thank you for your kind reply, mufeili.

I got it.
I’ll consider another implementation methods.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.