dot#
- metatensor.dot(tensor_1: TensorMap, tensor_2: TensorMap) TensorMap[source]#
- Compute the dot product of two - TensorMap.- The two - TensorMapmust have the same- keys. The resulting- TensorMapwill have the same keys as the input and each block will be the dot product of the two corresponding- TensorBlockin the input.- TensorBlockscorresponding to the same key must have the same- properties. The resulting- TensorBlocksof the dot product of two- TensorBlockshas- 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(["structure"], 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(["structure"], 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): ['structure'] components (): [] properties (2): ['structure'] gradients: None >>> print(tensor_dot.block(0).samples) Labels( structure 0 1 ) >>> print(tensor_dot.block(0).values) [[14 32] [32 77]] - Parameters:
- Returns:
- a - TensorMapwith the same keys of- Aand- B, and where each- TensorBlockhas: the- sampleequal to the- sampleof- A; the- propertiesequal to the- sampleof- B; and the- componentsequal to the- componentsof- A
- Return type: