Skip to content

Commit

Permalink
feat: len
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman committed Sep 25, 2024
1 parent 7b1a499 commit 354be69
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/coordinax/_src/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,33 @@ def T(self) -> "Self": # noqa: N802
# ---------------------------------------------------------------
# Methods

def __len__(self) -> int:
"""Return the length of the vector.
Examples
--------
>>> from unxt import Quantity
>>> import coordinax as cx
Scalar vectors have length 0:
>>> vec = cx.CartesianPosition1D.constructor([1], "m")
>>> len(vec)
0
Vectors with certain lengths:
>>> vec = cx.CartesianPosition1D(Quantity([1], "m"))
>>> len(vec)
1
>>> vec = cx.CartesianPosition1D(Quantity([1, 2], "m"))
>>> len(vec)
2
"""
return self.shape[0] if self.ndim > 0 else 0

def __abs__(self) -> Quantity:
"""Return the norm of the vector.
Expand Down

0 comments on commit 354be69

Please sign in to comment.