2026 USAAIO Round 1 Sample problems, Problem 4

Problem 4.

Copy the following code:
import numpy as np
Do the following coding tasks.

Part 4.1.

Generate a NumPy array with shape (5,8,3,1,2). Each entry is a standard normal.
Use random seed 2026.

Part 4.2.

Remove the dimension whose length is 1.

Part 4.3.

Insert a new dimension at axis 2.

Part 4.4.

Swap axes 0 and 1.

Part 4.5.

For those entries whose values are above 1, reset their values as 100.

Part 4.6.

Flatten the array.

1 Like

Part 4.1.

np.random.seed(2026)
arr = np.random.randn(5, 8, 3, 1, 2)
print(arr)

Part 4.2.

arr = np.squeeze(arr)
print(arr.shape)

Part 4.3.

arr = np.expand_dims(arr, axis=2)
print(arr.shape)

Part 4.4.

arr = np.swapaxes(arr, 0, 1)
print(arr.shape)

Part 4.5.

arr[arr > 1] = 100
print(arr)

Part 4.6.

arr = np.ndarray.flatten(arr)
print(arr.shape)
1 Like