<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_networkx(cls, graph, weight='weight'):
 r"""Import a graph from NetworkX. Edge weights are retrieved as an edge attribute, under the name specified by the ``weight`` parameter. Signals are retrieved from node attributes, and stored in the :attr:`signals` dictionary under the attribute name. `N`-dimensional signals that were broken during export are joined. Parameters graph : :class:`networkx.Graph` A NetworkX graph object. weight : string or None, optional The edge attribute that holds the numerical values used as the edge weights. All edge weights are set to 1 if None, or not found. Returns ------- graph : :class:`~pygsp.graphs.Graph` A PyGSP graph object. Notes ----- The nodes are ordered according to :meth:`networkx.Graph.nodes`. In NetworkX, node attributes need not be set for every node. If a node attribute is not set for a node, a NaN is assigned to the corresponding signal for that node. If the graph is a :class:`networkx.MultiGraph`, multiedges are aggregated by summation. See Also -------- from_graphtool : import from graph-tool load : load from a file Examples -------- NodeView((1, 2, 3, 4)) array([[0. , 0.2, 0. , 0. ], [0.2, 0. , 0.9, 0. ], [0. , 0.9, 0. , 0. ], [0. , 0. , 0. , 0. ]]) {'sig': array([ nan, nan, nan, 3.1416])} """

        nx = _import_networkx()
        from .graph import Graph

        adjacency = nx.to_scipy_sparse_matrix(graph, weight=weight)
        graph_pg = Graph(adjacency)

        for i, node in enumerate(graph.nodes()):
            for name in graph.nodes[node].keys():
                try:
                    signal = graph_pg.signals[name]
                except KeyError:
                    signal = np.full(graph_pg.n_vertices, np.nan)
                    graph_pg.set_signal(signal, name)
                try:
                    signal[i] = graph.nodes[node][name]
                except KeyError:
                    pass  # attribute not set for node

        graph_pg._join_signals()
        return graph_pg