Multilinear
Tensor arithmetic.
Prefixed by ten... (tensor).
Handle multiaxis vectors, that for example represent multivariate polynomials.
Tensors are accepted as numpy.array_like and returned as numpy.ndarrays.
Broadcasting happens similar to numpys broadcasting,
but the axes are matched in ascending order instead of descending order, and
the arrays don't get stretched but rather padded with zeros.
creation
tenzero = np.zeros((), dtype=object)
Zero tensor.
An empty array.
Notes
Why shape (0,) (=one dimensional, zero length) instead of () (zero dimensional)?
Shape () would be size one (empty product) and a scalar that could have any nonzero value.
Dimensionality of one isn't perfect, but at least its size is then zero and it couldn't be any arbitrary value.
tenbasis(i, c=1)
Return a basis tensor.
Returns a numpy.ndarray with i+1 zeros in each direction and a c in
the outer corner.
Source code in vector\multilinear\creation.py
28 29 30 31 32 33 34 35 36 37 38 39 40 | |
tenrand(*d)
Return a random tensor 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).
See also
- wraps:
numpy.random.rand
Source code in vector\multilinear\creation.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
tenrandn(*d)
Return a random tensor 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).
See also
- wraps:
numpy.random.randn
Source code in vector\multilinear\creation.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
utility
tenrank(t)
Return the rank.
See also
- wraps:
numpy.ndarray.ndim
Source code in vector\multilinear\utility.py
9 10 11 12 13 14 15 16 17 18 19 20 | |
tendim(t)
Return the dimensionalities.
See also
- wraps:
numpy.ndarray.shape
Source code in vector\multilinear\utility.py
22 23 24 25 26 27 28 29 30 31 32 33 | |
teneq(s, t)
Return whether two tensors are equal.
Source code in vector\multilinear\utility.py
35 36 37 38 39 40 41 42 | |
tentrim(t, tol=None)
Remove all trailing near zero (abs(t_i)<=tol) coefficients.
tol may also be None,
then all coefficients that evaluate to False are trimmed.
Notes
- Cutting of elements that are
abs(t_i)<=tolinstead ofabs(t_i)<tolto allow cutting of elements that are exactly zero bytrim(t, 0)instead oftrim(t, sys.float_info.min).
Source code in vector\multilinear\utility.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
tenrshift(t, n)
Shift coefficients up.
See also
- wraps:
numpy.pad
Source code in vector\multilinear\utility.py
68 69 70 71 72 73 74 75 | |
tenlshift(t, n)
Shift coefficients down.
See also
- wraps:
numpy.pad
Source code in vector\multilinear\utility.py
77 78 79 80 81 82 83 84 | |
hilbert_space
tenconj(t)
Return the elementwise complex conjugate.
See also
- one-dimensional:
vecconj - wraps:
numpy.conjugate
Source code in vector\multilinear\hilbert_space.py
9 10 11 12 13 14 15 16 17 18 19 20 21 | |
tenprod(s, t)
Return the tensor product.
See also
- wraps: `numpy.tensordot
Source code in vector\multilinear\hilbert_space.py
23 24 25 26 27 28 29 30 31 32 33 34 | |
vector_space
tenpos(t)
Return the identity.
See also
- wraps:
numpy.positive
Source code in vector\multilinear\vector_space.py
11 12 13 14 15 16 17 18 19 20 21 22 | |
tenneg(t)
Return the negation.
See also
- wraps:
numpy.negative
Source code in vector\multilinear\vector_space.py
24 25 26 27 28 29 30 31 32 33 34 35 | |
tenadd(*ts)
Return the sum.
See also
- for sum on a single coefficient:
tenaddc
Source code in vector\multilinear\vector_space.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
tenaddc(t, c, i=(0,))
Return the sum with a basis tensor.
More efficient than tenadd(t, tenbasis(i, c)).
See also
- for sum on more coefficients:
tenadd
Source code in vector\multilinear\vector_space.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
tensub(s, t)
Return the difference.
See also
- for difference on a single coefficient:
tensubc
Source code in vector\multilinear\vector_space.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
tensubc(t, c, i=(0,))
Return the difference with a basis tensor.
More efficient than tensub(t, tenbasis(i, c)).
See also
- for difference on more coefficients:
tensub
Source code in vector\multilinear\vector_space.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
tenmul(t, a)
Return the product.
See also
- wraps:
numpy.multiply
Source code in vector\multilinear\vector_space.py
113 114 115 116 117 118 119 120 121 122 123 124 | |
tenrmul(a, t)
Return the product.
See also
- wraps:
numpy.multiply
Source code in vector\multilinear\vector_space.py
126 127 128 129 130 131 132 133 134 135 136 137 | |
tentruediv(t, a)
Return the true quotient.
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.
See also
- wraps:
numpy.divide
Source code in vector\multilinear\vector_space.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
tenfloordiv(t, a)
Return the floor quotient.
See also
- wraps:
numpy.floor_divide
Source code in vector\multilinear\vector_space.py
163 164 165 166 167 168 169 170 171 172 173 174 | |
tenmod(t, a)
Return the remainder.
See also
- wraps:
numpy.mod
Source code in vector\multilinear\vector_space.py
176 177 178 179 180 181 182 183 184 185 186 187 | |
tendivmod(t, a)
Return the floor quotient and remainder
See also
- wraps:
numpy.divmod
Source code in vector\multilinear\vector_space.py
189 190 191 192 193 194 195 196 197 198 199 200 | |
elementwise
tenhadamard(*ts)
Return the elementwise product.
Source code in vector\multilinear\elementwise.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
tenhadamardtruediv(s, t)
Return the elementwise true quotient.
Source code in vector\multilinear\elementwise.py
29 30 31 32 33 34 35 36 37 | |
tenhadamardfloordiv(s, t)
Return the elementwise floor quotient.
Source code in vector\multilinear\elementwise.py
39 40 41 42 43 44 45 46 47 | |
tenhadamardmod(s, t)
Return the elementwise remainder.
Source code in vector\multilinear\elementwise.py
49 50 51 52 53 54 55 56 57 | |
tenhadamarddivmod(s, t)
Return the elementwise floor quotient and remainder.
Source code in vector\multilinear\elementwise.py
59 60 61 62 63 64 65 66 67 | |
tenhadamardmin(*ts, key=None)
Return the elementwise minimum.
Source code in vector\multilinear\elementwise.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
tenhadamardmax(*ts, key=None)
Return the elementwise maximum.
Source code in vector\multilinear\elementwise.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |