Skip to content

Consistent interface for (directed) graph creation #78

@sdmccabe

Description

@sdmccabe

This toy example suggests a problem with our current approach to creating graphs:

In [13]: A = np.array([[0,1,0],[1,0,1],[0,0,0]])                                                                                                                                               

In [14]: A                                                                                                                                                                                     
Out[14]: 
array([[0, 1, 0],
       [1, 0, 1],
       [0, 0, 0]])

In [15]: import networkx as nx                                                                                                                                                                 

In [16]: G = nx.from_numpy_array(A)                                                                                                                                                            

In [17]: G.is_directed()                                                                                                                                                                       
Out[17]: False

It seems that if we have an asymmetric matrix we need to be explicit about using the nx.DiGraph constructor.

A utility function for determining which graph constructor to use (and performing other potentially useful preprocessing, like removing self-loops) would probably be useful here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions