In-place
Vector in-place operations.
>>> from vector import vecimul
>>> v = [1, 2, 3]
>>> vecimul(2, v)
[2, 4, 6]
>>> v
[2, 4, 6]
Prefixed by veci... (vector - in-place).
All functions accept vectors as lists.
They modify them in-place.
The functions are type-independent. However, the coefficients used must support necessary scalar operations. For instance, for vector addition, coefficients must be addable.
For complete type safety a zero argument is available. Default is int(0).
Docstring conventions
Summary
Math notation (vector notation if possible, index notation, domain & codomain)
More information ("More efficient than ...").
Notes
Design choices
See also
Similar functions
References
Wikipedia, numpy, ...
creation
vecizero()
Return a zero vector.
An empty list: [].
Source code in vector\inplace\creation.py
12 13 14 15 16 17 18 19 20 21 | |
vecibasis(i, c=1, zero=0)
Return a basis vector.
Returns a list with i many zeros followed by c.
See also
- for all basis vectors:
vecibases
Source code in vector\inplace\creation.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
vecibases(start=0, c=1, zero=0)
Yield all basis vectors.
See also
- for single basis vector:
vecibasis
Source code in vector\inplace\creation.py
38 39 40 41 42 43 44 45 46 47 48 49 50 | |
vecirand(n)
Return a random vector of uniform sampled float coefficients.
The coefficients are sampled from a uniform distribution in [0, 1[.
Notes
Naming like numpy.random,
because seems more concise (not random & gauss as in the stdlib).
Source code in vector\inplace\creation.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
vecirandn(n, normed=True, mu=0, sigma=1, weights=None)
Return a random vector of normal sampled float coefficients.
The coefficients are sampled from a normal distribution.
Notes
Naming like numpy.random,
because seems more concise (not random & gauss as in the stdlib).
Source code in vector\inplace\creation.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
utility
vecitrim(v, tol=None)
Remove all trailing near zero (abs(v_i)<=tol) coefficients.
tol may also be None,
then all coefficients that evaluate to False are trimmed.
Notes
- Cutting of elements that are
abs(v_i)<=tolinstead ofabs(v_i)<tolto allow cutting of elements that are exactly zero bytrim(v, 0)instead oftrim(v, sys.float_info.min).
Source code in vector\inplace\utility.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
vecirshift(v, n, zero=0)
Shift coefficients up.
Source code in vector\inplace\utility.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
vecilshift(v, n)
Shift coefficients down.
Source code in vector\inplace\utility.py
46 47 48 49 50 51 52 53 54 55 56 57 58 | |
hilbert_space
veciconj(v)
Complex conjugate.
Tries to call a method conjugate on each element.
If not found, simply keeps the element as is.
Source code in vector\inplace\hilbert_space.py
9 10 11 12 13 14 15 16 17 18 19 20 21 | |
vector_space
vecipos(v)
Apply unary positive.
Source code in vector\inplace\vector_space.py
6 7 8 9 10 11 12 13 14 15 | |
vecineg(v)
Negate.
Source code in vector\inplace\vector_space.py
17 18 19 20 21 22 23 24 25 26 | |
veciadd(v, *ws)
Add.
See also
- for sum on a single coefficient:
veciaddc
Source code in vector\inplace\vector_space.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
veciaddc(v, c, i=0, zero=0)
Add a basis vector.
More efficient than veciadd(v, vecibasis(i, c)).
See also
- for sum on more coefficients:
veciadd
Source code in vector\inplace\vector_space.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
vecisub(v, w)
Subtract.
See also
- for difference on a single coefficient:
vecisubc
Source code in vector\inplace\vector_space.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
vecisubc(v, c, i=0, zero=0)
Subtract a basis vector.
More efficient than vecisub(v, vecibasis(i, c)).
See also
- for difference on more coefficients:
vecisub
Source code in vector\inplace\vector_space.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
vecimul(v, a)
Multiply.
Source code in vector\inplace\vector_space.py
110 111 112 113 114 115 116 117 118 119 | |
vecitruediv(v, a)
True divide.
Notes
Why called truediv instead of div?
divwould be more appropriate for an absolute clean mathematical implementation, that doesn't care about the language used. But the package might be used for pure integers/integer arithmetic, so both,truedivandfloordivoperations have to be provided, and none should be privileged over the other by getting the universaldivname.truediv/floordivis unambiguous, like Pythonoperators.
Source code in vector\inplace\vector_space.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
vecifloordiv(v, a)
Floor divide.
Source code in vector\inplace\vector_space.py
143 144 145 146 147 148 149 150 151 152 | |
vecimod(v, a)
Mod.
Source code in vector\inplace\vector_space.py
154 155 156 157 158 159 160 161 162 163 | |
elementwise
vecihadamard(v, *ws)
Return the elementwise product.
Source code in vector\inplace\elementwise.py
6 7 8 9 10 11 12 13 14 15 16 17 18 | |
vecihadamardtruediv(v, w)
Return the elementwise true quotient.
Source code in vector\inplace\elementwise.py
20 21 22 23 24 25 26 27 28 29 | |
vecihadamardfloordiv(v, w)
Return the elementwise floor quotient.
Source code in vector\inplace\elementwise.py
31 32 33 34 35 36 37 38 39 40 | |
vecihadamardmod(v, w)
Return the elementwise remainder.
Source code in vector\inplace\elementwise.py
42 43 44 45 46 47 48 49 50 51 | |