From 0d38b95da7d8a3ac4df1806a2cf1c83048078468 Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Mon, 5 Jun 2023 11:31:52 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9Aupdate=20documentation=20+=20?= =?UTF-8?q?=F0=9F=96=A4=20make=20black=20happy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/detection/core.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index d3901418..dc88e9cc 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -469,7 +469,35 @@ class Detections: raise ValueError(f"{anchor} is not supported.") - def __getitem__(self, index: Union[int, slice, List[int], np.ndarray]) -> Detections: + def __getitem__( + self, index: Union[int, slice, List[int], np.ndarray] + ) -> Detections: + """ + Get a subset of the Detections object. + + Args: + index (Union[int, slice, List[int], np.ndarray]): The index or indices of the subset of the Detections + + Returns: + (Detections): A subset of the Detections object. + + Example: + ```python + >>> import supervision as sv + + >>> detections = sv.Detections(...) + + >>> first_detection = detections[0] + + >>> first_10_detections = detections[0:10] + + >>> some_detections = detections[[0, 2, 4]] + + >>> class_0_detections = detections[detections.class_id == 0] + + >>> high_confidence_detections = detections[detections.confidence > 0.5] + ``` + """ if isinstance(index, int): index = [index] return Detections(