Ask Your Question

Error in datastructure in sagemath

asked 2020-03-14 18:58:33 -0600

MrsO gravatar image

updated 2020-03-16 07:38:28 -0600

FrédéricC gravatar image

I am new to creating a graph. I am trying to analyse a code by recreating it. My sample code is given below:

time_window_interval = [0, 4*60]
g = g.to_directed(time_window_interval)

On running the code, I am getting "ValueError: data_structure must be equal to 'sparse', 'static_sparse' or 'dense'" on the line g = g.to_directed(time_window_interval).

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2020-03-16 03:25:26 -0600

Sébastien gravatar image

updated 2020-03-18 14:04:32 -0600

Once you create the graph:

sage: g = graphs.CompleteGraph(5)
sage: g
Complete graph: Graph on 5 vertices

This is what happens if you provide wrong input:

sage: g.to_directed('wrong input')
Traceback (most recent call last)
ValueError: data_structure must be equal to 'sparse', 'static_sparse' or 'dense'

Following what the documentation of the method to_directed for undirected graphs says, you may instead write:

sage: g.to_directed('dense')
Complete graph: Digraph on 5 vertices

You may also create a directed graph directly using DiGraph (various different type of inputs), see the documentation.

edit flag offensive delete link more


Thanks.. I used g.to_directed() without any input. That also worked..

MrsO gravatar imageMrsO ( 2020-03-16 16:51:09 -0600 )edit

answered 2020-03-16 02:23:27 -0600

vdelecroix gravatar image
edit flag offensive delete link more


each question is a duplicate of itself:)

Sébastien gravatar imageSébastien ( 2020-03-16 03:13:06 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2020-03-14 18:58:33 -0600

Seen: 68 times

Last updated: Mar 18 '20