returns a unit basis vector with a One at index 'pos' (indexing at 0)
(dimension: int, pos: int)
| 203 | |
| 204 | |
| 205 | def unit_basis_vector(dimension: int, pos: int) -> Vector: |
| 206 | """ |
| 207 | returns a unit basis vector with a One |
| 208 | at index 'pos' (indexing at 0) |
| 209 | """ |
| 210 | # precondition |
| 211 | assert isinstance(dimension, int) |
| 212 | assert isinstance(pos, int) |
| 213 | ans = [0] * dimension |
| 214 | ans[pos] = 1 |
| 215 | return Vector(ans) |
| 216 | |
| 217 | |
| 218 | def axpy(scalar: float, x: Vector, y: Vector) -> Vector: |