<｜begin▁of▁sentence｜>### Instruction:
Given a graph with nodes 1, 2, 3, and 4 and edges (1,2), (2,3), and (3,4), how would you compute the Laplacian matrix? The Laplacian matrix should reflect the structure of the graph where each diagonal element is the degree of the corresponding node, and the off-diagonal elements are -1 if there is an edge between the corresponding nodes, and 0 otherwise.
### Response:
import networkx as nx
from scipy.sparse import csr_matrix
# Create a graph
G = nx.Graph()
# Add edges to the graph
G.add_edges_from([(1, 2), (2, 3), (3, 4)])
# Get the Laplacian matrix of the graph
L = nx.laplacian_matrix(G)
# Convert to a regular array
laplacian = L.toarray()
print(laplacian)
<|EOT|>
