<｜begin▁of▁sentence｜>### Instruction:
Given a weighted undirected graph G with nodes 1, 2, 3, 4 and edges (1-2, weight 1), (2-3, weight 2), (3-4, weight 1), (4-1, weight 2), and (1-3, weight 1), how would you compute its spectral ordering, considering the weights of the edges and ensuring that nodes in the same weakly connected components appear contiguous and ordered by their corresponding elements in the Fiedler vector of the component?
### Response:
import networkx as nx
from networkx.linalg.spectrum import spectral_ordering

# Create a graph
G = nx.Graph()
G.add_edges_from([(1, 2, {'weight': 1}), (2, 3, {'weight': 2}), (3, 4, {'weight': 1}), (4, 1, {'weight': 2}), (1, 3, {'weight': 1})])

# Compute the spectral ordering
ordering = spectral_ordering(G, weight='weight', normalized=True)

print('Spectral Ordering:', ordering)
<|EOT|>
