MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / dict_product

Function dict_product

tests/test_utils.py:916–933  ·  view source on GitHub ↗

Create cartesian product, equivalent to a nested for-loop, combinations of the items dict. Args: items: dict of items to be combined. Returns: list: list of dictionaries with the combinations of the input items. Example: >>> dict_product(x=[1, 2], y=[3, 4])

(**items: Iterable[Any])

Source from the content-addressed store, hash-verified

914
915
916def dict_product(**items: Iterable[Any]) -> list[dict]:
917 """Create cartesian product, equivalent to a nested for-loop, combinations of the items dict.
918
919 Args:
920 items: dict of items to be combined.
921
922 Returns:
923 list: list of dictionaries with the combinations of the input items.
924
925 Example:
926 >>> dict_product(x=[1, 2], y=[3, 4])
927 [{'x': 1, 'y': 3}, {'x': 1, 'y': 4}, {'x': 2, 'y': 3}, {'x': 2, 'y': 4}]
928 """
929 keys = items.keys()
930 values = items.values()
931 prod_values = product(*values)
932 prod_dict = [dict(zip(keys, v)) for v in prod_values]
933 return prod_dict
934
935
936if __name__ == "__main__":

Callers 15

test_padMethod · 0.90
test_segresnet.pyFile · 0.90
test_vitautoenc.pyFile · 0.90
test_mednext.pyFile · 0.90
test_unetr.pyFile · 0.90
test_swin_unetr.pyFile · 0.90
test_transchex.pyFile · 0.90
test_dynunet.pyFile · 0.90
test_vit.pyFile · 0.90
test_CABlock.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…