<｜begin▁of▁sentence｜>### Instruction:
If you have a position dictionary for the nodes of a graph where the keys are node identifiers and the values are NumPy arrays representing their positions in a two-dimensional space, how can you rescale all positions so that the graph layout is scaled to fit within a specified range in all axes while preserving the aspect ratio?
### Response:
import numpy as np
import networkx as nx

# Suppose we have a graph with a position dictionary for each node
pos = {0: np.array([0, 0]), 1: np.array([1, 2]), 2: np.array([2, 1])}
# Convert the dictionary to just a list of positions
pos_array = np.array(list(pos.values()))

# Rescale the positions using networkx's rescale_layout
scaled_pos = nx.drawing.layout.rescale_layout(pos_array, scale=2)

print(scaled_pos)
<|EOT|>
