GCXS.mean
- GCXS.mean(axis=None, keepdims=False, dtype=None, out=None)
Compute the mean along the given axes. Uses all axes by default.
- Parameters:
axis (Union[int, Iterable[int]], optional) – The axes along which to compute the mean. Uses all axes by default.
keepdims (bool, optional) – Whether or not to keep the dimensions of the original array.
dtype (numpy.dtype) – The data type of the output array.
- Returns:
The reduced output sparse array.
- Return type:
See also
numpy.ndarray.meanEquivalent numpy method.
scipy.sparse.coo_matrix.meanEquivalent Scipy method.
Notes
This function internally calls
COO.sum_duplicatesto bring the array into canonical form.The
outparameter is provided just for compatibility with Numpy and isn’t actually supported.
Examples
You can use
COO.meanto compute the mean of an array across any dimension.>>> from sparse import COO >>> x = np.array([[1, 2, 0, 0], [0, 1, 0, 0]], dtype="i8") >>> s = COO.from_numpy(x) >>> s2 = s.mean(axis=1) >>> s2.todense() array([0.5, 1.5, 0., 0.])
You can also use the
keepdimsargument to keep the dimensions after the mean.>>> s3 = s.mean(axis=0, keepdims=True) >>> s3.shape (1, 4)
You can pass in an output datatype, if needed.
>>> s4 = s.mean(axis=0, dtype=np.float16) >>> s4.dtype dtype('float16')
By default, this reduces the array down to one number, computing the mean along all axes.
>>> s.mean() 0.5