Binary Operations on Arrays¶
Tensor |
Einstein |
Nutils |
|||
---|---|---|---|---|---|
1 |
\(\mathbf{a} \in \mathbb{R}^n\) |
\(\mathbf{b} \in \mathbb{R}^n\) |
\(c = \mathbf{a} \cdot \mathbf{b} \in \mathbb{R}\) |
\(c = a_i b_i\) |
|
2 |
\(\mathbf{a} \in \mathbb{R}^n\) |
\(\mathbf{b} \in \mathbb{R}^m\) |
\(\mathbf{C} = \mathbf{a} \otimes \mathbf{b} \in \mathbb{R}^{n \times m}\) |
\(C_{ij} = a_i b_j\) |
|
|
|||||
3 |
\(\mathbf{A} \in \mathbb{R}^{m \times n}\) |
\(\mathbf{b} \in \mathbb{R}^n\) |
\(\mathbf{c} = \mathbf{A}\mathbf{b} \in \mathbb{R}^{m}\) |
\(c_{i} = A_{ij} b_j\) |
|
4 |
\(\mathbf{A} \in \mathbb{R}^{m \times n}\) |
\(\mathbf{B} \in \mathbb{R}^{n \times p}\) |
\(\mathbf{C} = \mathbf{A} \mathbf{B} \in \mathbb{R}^{m \times p}\) |
\(c_{ij} = A_{ik} B_{kj}\) |
|
5 |
\(\mathbf{A} \in \mathbb{R}^{m \times n}\) |
\(\mathbf{B} \in \mathbb{R}^{p \times n}\) |
\(\mathbf{C} = \mathbf{A} \mathbf{B}^T \in \mathbb{R}^{m \times p}\) |
\(C_{ij} = A_{ik} B_{jk}\) |
|
|
|||||
6 |
\(\mathbf{A} \in \mathbb{R}^{m \times n}\) |
\(\mathbf{B} \in \mathbb{R}^{m \times n}\) |
\(c = \mathbf{A} : \mathbf{B} \in \mathbb{R}\) |
\(c = A_{ij} B_{ij}\) |
|
Notes:
In the above table the summation axes are numbered backward. For example,
sum(-1)
is used to sum over the last axis of an array. Although forward numbering is possible in many situations, backward numbering is generally preferred in Nutils code.When a summation over multiple axes is performed (#6), these axes are to be listed. In the case of single-axis summations listing is optional (for example
sum(-1)
is equivalent tosum([-1])
). The shorter notationsum(-1)
is preferred.When the number of dimensions of the two arguments of a binary operation mismatch, singleton axes are automatically prepended to the “shorter” argument. This property can be used to shorten notation. For example, #3 can be written as
(A*b).sum(-1)
. To avoid ambiguities, in general, such abbreviations are discouraged.