Ask Your Question

Error in datastructure in sagemath

asked 2020-03-15 00:58:33 +0200

MrsO gravatar image

updated 2020-03-16 13:38:28 +0200

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 09:25:26 +0200

Sébastien gravatar image

updated 2020-03-18 20:04:32 +0200

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 22:51:09 +0200 )edit

answered 2020-03-16 08:23:27 +0200

vdelecroix gravatar image
edit flag offensive delete link more


each question is a duplicate of itself:)

Sébastien gravatar imageSébastien ( 2020-03-16 09:13:06 +0200 )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-15 00:58:33 +0200

Seen: 259 times

Last updated: Mar 18 '20