Skip to content

Commit a0ce360

Browse files
committed
add clip
1 parent 0f024b6 commit a0ce360

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/pint_array/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,17 @@ def prod(x, /, *args, axis=None, **kwargs):
714714

715715
mod.prod = prod
716716

717+
def clip(x, /, min=None, max=None):
718+
x = asarray(x)
719+
units = x.units
720+
magnitude_x = xp.asarray(x.magnitude, copy=True)
721+
magnitude_min = min.m_as(units) if hasattr(min, "units") else min
722+
magnitude_max = max.m_as(units) if hasattr(max, "units") else max
723+
magnitude = xp.clip(magnitude_x, magnitude_min, magnitude_max)
724+
return ArrayUnitQuantity(magnitude, units)
725+
726+
mod.clip = clip
727+
717728
preface = [
718729
"The following is the documentation for the corresponding "
719730
f"attribute of `{xp.__name__}`.",

0 commit comments

Comments
 (0)