if not self.is_dimensionless():
raise NotImplementedError("Product over array elements on quantities "
"with dimensions is not implemented.")
return Quantity(np.asarray(self).prod(*args, **kwds))
def cumprod(self, *args, **kwds):
if not self.is_dimensionless():
raise NotImplementedError("Product over array elements on quantities "
After Change
searchsorted.__doc__ = np.ndarray.searchsorted.__doc__
def prod(self, *args, **kwds):
prod_result = super(Quantity, self).prod(*args, **kwds)
// Calculating the correct dimensions is not completly trivial (e.g.
// like doing self.dim**self.size) because prod can be called on
// multidimensional arrays along a certain axis.
// Our solution: Use a "dummy matrix" containing a 1 (without units) at
// each entry and sum it, using the same keyword arguments as provided.
// The result gives the exponent for the dimensions.
// This relies on sum and prod having the same arguments, which is true
// now and probably remains like this in the future
dim_exponent = np.ones_like(self).sum(*args, **kwds)
// The result is possibly multidimensional but all entries should be
// identical
if dim_exponent.size > 1:
dim_exponent = dim_exponent[0]
return Quantity.with_dimensions(prod_result, self.dim ** dim_exponent)
prod.__doc__ = np.ndarray.prod.__doc__
def cumprod(self, *args, **kwds):
if not self.is_dimensionless():