Skip to content
Advertisement

Changing graph dataset matrices from sparse format to dense

I am trying to use the CoRA dataset to train a graph neural network on tensorflow for the first time. The features and adjacency matrices provided by the dataset comes in a sparse representation but I don’t need it here. Thus, I want to use numpy’s todense() but it turns out it doesn’t exist. For your reference, here is the relevant code:

JavaScript

and the error is: “AttributeError: ‘numpy.ndarray’ object has no attribute ‘todense'”

I would like to know if there has been a replacement for todense() or any other ways to convert sparse representations to dense.

Advertisement

Answer

You can use tf.sparse.to_dense to convert sparse matrix to dense matrix.

Here is the example:

JavaScript

I hope that helps.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement