<｜begin▁of▁sentence｜>### Instruction:
A network scientist has an undirected and unweighted graph representing a social network, where nodes represent individuals and edges represent connections between individuals. They want to analyze the robustness of this social network by randomizing the edges while preserving the degree sequence of all nodes. The scientist uses the EdgeSwapper class from the graspologic package to perform a series of degree-preserving edge swaps. The example code demonstrates how to use the EdgeSwapper class to generate a new adjacency matrix after performing a number of edge swaps on the original network. The goal is to verify that the degree sequence of the new network is the same as the original while the edges have been randomized. How can the scientist use this EdgeSwapper class to achieve such randomization, and how to ensure that the degree sequences are indeed equal?
### Response:
import networkx as nx
from graspologic.models import EdgeSwapper
import numpy as np

# Step 1: Construct an undirected and unweighted social network graph
n = 100  # Number of nodes in the graph
p = 0.05  # Probability of edge creation
np.random.seed(42)
G = nx.erdos_renyi_graph(n, p)

# Convert the NetworkX graph to an adjacency matrix
adjacency_matrix = nx.to_numpy_array(G)

# Step 2: Use EdgeSwapper to perform degree-preserving edge swaps
# Initialize the EdgeSwapper with the adjacency matrix
edge_swapper = EdgeSwapper(adjacency=adjacency_matrix, seed=42)

# Perform a number of edge swaps equal to the number of edges in the graph
n_swaps = G.number_of_edges()
new_adjacency_matrix, new_edge_list = edge_swapper.swap_edges(n_swaps=n_swaps)

# Step 3: Generate a new network with the same degree sequence
# Convert the new adjacency matrix back to a NetworkX graph
new_G = nx.from_numpy_array(new_adjacency_matrix)

# Verify that the degree sequence is preserved
original_degree_sequence = [d for n, d in G.degree()]
new_degree_sequence = [d for n, d in new_G.degree()]

print("Degree sequences are equal:", original_degree_sequence == new_degree_sequence)
<|EOT|>
