<｜begin▁of▁sentence｜>### Instruction:
A network scientist has a graph generated from a stochastic block model with 50 nodes divided into 2 blocks, each consisting of 25 nodes. The blocks have a high probability of internal connections (0.5) and a lower probability of connections between the blocks (0.1). The scientist wishes to fit a stochastic block model to the graph to learn the block structures and the respective probabilities of connections within and between these blocks. After fitting the model, the scientist also wants to generate a new graph sample from the fitted model.
### Response:
import numpy as np
import networkx as nx
from graspologic.models import SBMEstimator

# Step 1: Generate synthetic graph
n = 50  # number of nodes
p = np.array([[0.5, 0.1], [0.1, 0.5]])
labels = np.random.choice([0, 1], size=n)
G = nx.stochastic_block_model(sizes=[25, 25], p=p, labels=labels)

# Step 2: Fit the SBMEstimator to the graph
sbm = SBMEstimator(directed=False, loops=False)
sbm.fit(nx.to_numpy_array(G), y=labels)

# Output the block probability matrix
print(sbm.block_p_)

# Generate a new graph sample from the fit model
new_graph_sample = sbm.sample()[0]

# Convert to networkx graph
new_G = nx.from_numpy_array(new_graph_sample)
print(nx.info(new_G))
<|EOT|>
