split#
- metatensor.split(tensor: TensorMap, axis: str, grouped_labels: List[Labels]) List[TensorMap][source]#
- Split a - TensorMapinto multiple- TensorMap.- The operation is based on some specified groups of indices, along either the “samples” or “properties” - axis. The number of returned- TensorMap`s is equal to the number of :py:class:`Labelsobjects passed in- grouped_labels. Each returned :py:class`TensorMap` will have the same keys and number of blocks at the input- tensor, but with the dimensions of the blocks reduced to only contain the specified indices for the corresponding group.- For example, to split a tensor along the “samples” axis, according to the “structure” index, where structures 0, 6, and 7 are in the first returned :py:class`TensorMap`; 2, 3, and 4 in the second; and 1, 5, 8, 9, and 10 in the third: - import metatensor tensor_splitted = metatensor.split( tensor, axis="samples", grouped_labels=[ Labels(names=["structure"], values=np.array([[0], [6], [7]])), Labels(names=["structure"], values=np.array([[2], [3], [4]])), Labels(names=["structure"], values=np.array([[1], [5], [8], [10]])), ], ) - Parameters:
- axis (str) – a str, either “samples” or “properties”, that indicates the - TensorBlockaxis along which the named index (or indices) in- grouped_labelsbelongs. Each- TensorBlockin each returned- TensorMapcould have a reduced dimension along this axis, but the other axes will remain the same size.
- grouped_labels (List[Labels]) – a list of - Labelscontaining the names and values of the indices along the specified- axiswhich should be in each respective output- TensorMap.
 
- Returns:
- a list of:py:class:TensorMap that corresponds to the split input - tensor. Each tensor in the returned list contains only the named indices in the respective py:class:Labels object of- grouped_labels.
- Return type:
 
- metatensor.split_block(block: TensorBlock, axis: str, grouped_labels: List[Labels]) List[TensorBlock][source]#
- Splits an input - TensorBlockinto multiple- TensorBlockobjects based on some specified- grouped_labels, along either the “samples” or “properties”- axis. The number of returned- TensorBlock`s is equal to the number of :py:class:`Labelsobjects passed in- grouped_labels. Each returned :py:class`TensorBlock` will have the same keys and number of blocks at the input- tensor, but with the dimensions of the blocks reduced to only contain the specified indices for the corresponding group.- For example, to split a block along the “samples” axis, according to the “structure” index, where structures 0, 6, and 7 are in the first returned :py:class`TensorMap`; 2, 3, and 4 in the second; and 1, 5, 8, 9, and 10 in the third: - import metatensor block_splitted = metatensor.split_block( block, axis="samples", grouped_labels=[ Labels(names=["structure"], values=np.array([[0], [6]])), Labels(names=["structure"], values=np.array([[2], [3]])), Labels(names=["structure"], values=np.array([[1], [5], [10]])), ], ) - Parameters:
- block (TensorBlock) – a - TensorBlockto be split
- axis (str) – a str, either “samples” or “properties”, that indicates the - TensorBlockaxis along which the named index (or indices) in- grouped_labelsbelongs. Each- TensorBlockreturned could have a reduced dimension along this axis, but the other axes will remain the same size.
- grouped_labels (List[Labels]) – a list of - Labelscontaining the names and values of the indices along the specified- axiswhich should be in each respective output- TensorBlock.
 
- Returns:
- a list of:py:class:TensorBlock that corresponds to the split input - block. Each block in the returned list contains only the named indices in the respective py:class:Labels object of- grouped_labels.
- Return type: