dot¶
- metatensor.dot(tensor_1: TensorMap, tensor_2: TensorMap) TensorMap[source]¶
Compute the dot product of two
TensorMap.The two
TensorMapmust have the samekeys. The resultingTensorMapwill have the same keys as the input and each block will be the dot product of the two correspondingTensorBlockin the input.TensorBlockscorresponding to the same key must have the sameproperties. The resultingTensorBlocksof the dot product of twoTensorBlockshasresult_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
TensorMapwith the same keys ofAandB, and where eachTensorBlockhas: thesampleequal to thesampleofA; thepropertiesequal to thesampleofB; and thecomponentsequal to thecomponentsofA- Return type: