returns a unit basis vector with a One at index 'pos' (indexing at 0)
(dimension, pos)
| 208 | |
| 209 | |
| 210 | def unitBasisVector(dimension, pos): |
| 211 | """ |
| 212 | returns a unit basis vector with a One |
| 213 | at index 'pos' (indexing at 0) |
| 214 | """ |
| 215 | # precondition |
| 216 | assert isinstance(dimension, int) and (isinstance(pos, int)) |
| 217 | ans = [] |
| 218 | for i in range(dimension): |
| 219 | if i != pos: |
| 220 | ans.append(0) |
| 221 | else: |
| 222 | ans.append(1) |
| 223 | return Vector(ans) |
| 224 | |
| 225 | |
| 226 | def axpy(scalar, x, y): |