---
title: "Python and Tensor Programming"
jupyter: python3
---

This bridge appendix reviews indexing, broadcasting, vectorization, and shape reasoning.

```{python}
import torch

batch = torch.arange(12, dtype=torch.float32).reshape(3, 4)
offset = torch.tensor([10.0, 20.0, 30.0, 40.0])
shifted = batch + offset
assert shifted.shape == (3, 4)
print(shifted)
```

## Checklist

- Replace loops with tensor operations only after the loop version is understood.
- Annotate expected shapes before running a cell.
- Use assertions at module boundaries.
