dot#
- metatensor.dot(tensor_1: TensorMap, tensor_2: TensorMap) TensorMap [source]#
Compute the dot product of two
TensorMap
.The two
TensorMap
must have the samekeys
. The resultingTensorMap
will have the same keys as the input and each block will be the dot product of the two correspondingTensorBlock
in the input.TensorBlocks
corresponding to the same key must have the sameproperties
. The resultingTensorBlocks
of the dot product of twoTensorBlocks
hasresult_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 ofA
andB
, and where eachTensorBlock
has: thesample
equal to thesample
ofA
; theproperties
equal to thesample
ofB
; and thecomponents
equal to thecomponents
ofA
- Return type: