Skip to content

Commit

Permalink
quantities: Make mean() more generic. (amusecode#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sbte authored Mar 20, 2024
1 parent 51443e9 commit 09117ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/amuse/test/suite/core_tests/test_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ def test34(self):
x[0] = -1
self.assertEqual(a, [1, 2, 3, 4, 5] | units.m)

def test_mean(self):
x = [1.0, 2.0, 3.0] | si.kg
mask = [True, True, False]
self.assertEqual(x.mean(), 2.0 | si.kg)
self.assertEqual(x.mean(where=mask), 1.5 | si.kg)


class TestAdaptingVectorQuantities(amusetest.TestCase):

Expand Down
4 changes: 2 additions & 2 deletions src/amuse/units/quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,8 @@ def transpose(self, axes=None):
def T(self):
return VectorQuantity(self.number.T, self.unit)

def mean(self, axis=None, dtype=None, out=None):
return new_quantity(self.number.mean(axis, dtype, out), self.unit)
def mean(self, *args, **kwargs):
return new_quantity(self.number.mean(*args, **kwargs), self.unit)

def median(self, **kwargs):
return new_quantity(numpy.median(self.number, **kwargs), self.unit)
Expand Down

0 comments on commit 09117ad

Please sign in to comment.