dot

metatensor.dot(tensor_1: TensorMap, tensor_2: TensorMap) TensorMap[source]

Compute the dot product of two TensorMap.

The two TensorMap must have the same keys. The resulting TensorMap will have the same keys as the input and each block will be the dot product of the two corresponding TensorBlock in the input.

TensorBlocks corresponding to the same key must have the same properties. The resulting TensorBlocks of the dot product of two TensorBlocks has result_block.values = block_1.values @ block_2.values.T

>>> import numpy as np
>>> from metatensor import Labels
>>> block_1 = TensorBlock(
...     values=np.array(
...         [
...             [1, 2, 3],
...             [4, 5, 6],
...         ]
...     ),
...     samples=Labels(["system"], np.array([[0], [1]])),
...     components=[],
...     properties=Labels(["properties"], np.array([[0], [1], [2]])),
... )
>>> block_2 = TensorBlock(
...     values=np.array(
...         [
...             [1, 2, 3],
...             [4, 5, 6],
...         ]
...     ),
...     samples=Labels(["system"], np.array([[0], [1]])),
...     components=[],
...     properties=Labels(["properties"], np.array([[0], [1], [2]])),
... )
>>> keys = Labels(names=["key"], values=np.array([[0]]))
>>> A = TensorMap(keys, [block_1])
>>> B = TensorMap(keys, [block_2])
>>> tensor_dot = dot(A, B)
>>> print(tensor_dot.block(0))
TensorBlock
    samples (2): ['system']
    components (): []
    properties (2): ['system']
    gradients: None
>>> print(tensor_dot.block(0).samples)
Labels(
    system
      0
      1
)
>>> print(tensor_dot.block(0).values)
[[14 32]
 [32 77]]
Parameters:
Returns:

a TensorMap with the same keys of A and B, and where each TensorBlock has: the sample equal to the sample of A; the properties equal to the sample of B; and the components equal to the components of A

Return type:

TensorMap