Complete worked example
python
import numpy as np
def inspect_example(rows):
data = np.array(rows, dtype=np.float64, copy=True)
if data.ndim != 2 or 0 in data.shape:
raise ValueError("a non-empty matrix is required")
if not np.isfinite(data).all():
raise ValueError("measurements must be finite")
return data- Reasoning
- Import NumPy as np, convert the supplied rows with an explicit float64 dtype, and inspect ndim before using two-axis indexing. The worked function rejects scalars, vectors, empty dimensions and non-finite values. A copy makes the returned data independent even when a caller supplies an array rather than a list. The lab checks the actual ndarray type, exact shape, dtype and values, so returning a visually similar nested list does not pass. Start by tracing a two-by-three example on paper. Each pair of coordinates selects one scalar. The shape belongs to the complete array, while each row view has its own one-dimensional shape. No model training or advanced mathematics is required to establish this boundary.