Skip to content

Drawing with spectral layout fails because numpy is not imported (migrated from Trac #601) #592

Closed

Description

@networkx-trac

Original ticket https://networkx.lanl.gov/trac/ticket/601
Reported 2011-07-18 by dirkmeister, assigned to @hagberg.

I have the following stack trace:
'''
File ".../networkx-1.5-py2.6.egg/networkx/drawing/nx_pylab.py", line 881, in draw_spectral
draw(G,spectral_layout(G),**kwargs)
File ".../networkx-1.5-py2.6.egg/networkx/drawing/layout.py", line 464, in spectral_layout
pos=_sparse_spectral(A,dim=dim,weighted=weighted)
File ".../networkx-1.5-py2.6.egg/networkx/drawing/layout.py", line 519, in _sparse_spectral
data=np.asarray(A.sum(axis=1).T)
NameError: global name 'np' is not defined
'''

The reason seems to be that numpy is not imported in _sparse_spectral, where as it is imported e.g. in _spectral. The error seems to still exist in the current source. Here the faulty line moved from line 519 to [https://networkx.lanl.gov/trac/browser/networkx/networkx/drawing/layout.py#L494 494]

I think it can be fixed by
'''
try:
import numpy as np
except ImportError:
raise ImportError("spectral_layout() requires numpy: http://scipy.org/ ")
}}

Activity

  1. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @dschult, 2011-07-21

    Even more subtle than that because the eigen_symmetric function has been renamed eigen.eigsh
    I'm pushing a patch and some tests to fix this. Thanks for the report!

  2. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by Dan Schult <dschult, 2011-07-21

    In [8edc325/networkx]:
    '''
    #!CommitTicketReference repository="networkx" revision="8edc3258a6e3efa2c3a508590a3113ebdbf24d89"
    fix sparse matrix spectral layout imports to import numpy
    and rename eigen_symmetric as eigen.eigsh
    Fixes #601
    '''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions