COO.std(axis=None, dtype=None, out=None, ddof=0, keepdims=False)

Compute the standard deviation along the given axes. Uses all axes by default.

  • axis (Union[int, Iterable[int]], optional) – The axes along which to compute the standard deviation. Uses all axes by default.

  • dtype (numpy.dtype, optional) – The output datatype.

  • out (SparseArray, optional) – The array to write the output to.

  • ddof (int) – The degrees of freedom.

  • keepdims (bool, optional) – Whether or not to keep the dimensions of the original array.


The reduced output sparse array.

Return type:


See also


Equivalent numpy method.


  • This function internally calls COO.sum_duplicates to bring the array into canonical form.


You can use COO.std to compute the standard deviation 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.std(axis=1)
>>> s2.todense()  
array([0.8291562, 0.4330127])

You can also use the keepdims argument to keep the dimensions after the standard deviation.

>>> s3 = s.std(axis=0, keepdims=True)
>>> s3.shape
(1, 4)

You can pass in an output datatype, if needed.

>>> s4 = s.std(axis=0, dtype=np.float16)
>>> s4.dtype

By default, this reduces the array down to one number, computing the standard deviation along all axes.

>>> s.std()