MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / unit_basis_vector

Function unit_basis_vector

linear_algebra/src/lib.py:205–215  ·  view source on GitHub ↗

returns a unit basis vector with a One at index 'pos' (indexing at 0)

(dimension: int, pos: int)

Source from the content-addressed store, hash-verified

203
204
205def 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
218def axpy(scalar: float, x: Vector, y: Vector) -> Vector:

Callers 1

Calls 1

VectorClass · 0.85

Tested by 1