MCPcopy Index your code
hub / github.com/geekcomputers/Python / unitBasisVector

Function unitBasisVector

linear-algebra-python/src/lib.py:210–223  ·  view source on GitHub ↗

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

(dimension, pos)

Source from the content-addressed store, hash-verified

208
209
210def 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
226def axpy(scalar, x, y):

Callers 1

test_unitBasisVectorMethod · 0.85

Calls 2

VectorClass · 0.85
appendMethod · 0.45

Tested by 1

test_unitBasisVectorMethod · 0.68