arkouda.array_api.statistical_functions¶
Functions¶
|
Compute the cumulative product of the elements of an array along a given axis. |
|
Compute the cumulative sum of the elements of an array along a given axis. |
|
Compute the maximum values of an array along a given axis or axes. |
|
Compute the minimum values of an array along a given axis or axes. |
|
|
|
Compute the mean of an array along a given axis or axes. |
|
Compute the product of an array along a given axis or axes. |
|
Compute the standard deviation of an array along a given axis or axes. |
|
Compute the sum of an array along a given axis or axes. |
|
Compute the variance of an array along a given axis or axes. |
Module Contents¶
- arkouda.array_api.statistical_functions.cumulative_prod(x: arkouda.array_api.array_object.Array, /, *, axis: int | None = None, dtype: arkouda.array_api._typing.Dtype | None = None, include_initial: bool = False) arkouda.array_api.array_object.Array[source]¶
Compute the cumulative product of the elements of an array along a given axis.
- Parameters:
x (Array) – The array to compute the cumulative product of
axis (int, optional) – The axis along which to compute the cumulative product. If x is 1D, this argument is optional, otherwise it is required.
dtype (Dtype, optional) – The dtype of the returned array. If None, the dtype of the input array is used.
include_initial (bool, optional) – Whether to include the initial value as the first element of the output.
- Returns:
A new array holding the result of the cumulative prod along the given axis.
- Return type:
- Raises:
ValueError – Raised if x is multi-dim and no axis was supplied.
IndexError – Raised if axis is invalid for the given array.
Examples
>>> import arkouda as ak >>> import arkouda.array_api as xp >>> a = xp.asarray((1 + ak.arange(6,dtype=ak.float64).reshape(2,3))) >>> xp.cumulative_prod(a,axis=0,include_initial=True) Arkouda Array ((3, 3), float64)[[1.0 1.0 1.0] [1.0 2.0 3.0] [4.0 10.0 18.0]] >>> xp.cumulative_prod(a,axis=1,include_initial=False) Arkouda Array ((2, 3), float64)[[1.0 2.0 6.0] [4.0 20.0 120.0]]
- arkouda.array_api.statistical_functions.cumulative_sum(x: arkouda.array_api.array_object.Array, /, *, axis: int | None = None, dtype: arkouda.array_api._typing.Dtype | None = None, include_initial: bool = False) arkouda.array_api.array_object.Array[source]¶
Compute the cumulative sum of the elements of an array along a given axis.
- Parameters:
x (Array) – The array to compute the cumulative sum of
axis (int, optional) – The axis along which to compute the cumulative sum. If x is 1D, this argument is optional, otherwise it is required.
dtype (Dtype, optional) – The dtype of the returned array. If None, the dtype of the input array is used.
include_initial (bool, optional) – Whether to include the initial value as the first element of the output.
- Returns:
A new array holding the result of the cumulative sum along the given axis.
- Return type:
- Raises:
ValueError – Raised if x is multi-dim and no axis was supplied.
IndexError – Raised if axis is invalid for the given array.
Examples
>>> import arkouda as ak >>> import arkouda.array_api as xp >>> a = xp.asarray((1 + ak.arange(10,dtype=ak.float64)).reshape(2,5)) >>> xp.cumulative_sum(a,axis=0,include_initial=True) Arkouda Array ((3, 5), float64)[[0.0 0.0 0.0 0.0 0.0] [1.0 2.0 3.0 4.0 5.0] [7.0 9.0 11.0 13.0 15.0]] >>> xp.cumulative_sum(a,axis=1,include_initial=False) Arkouda Array ((2, 5), float64)[[1.0 3.0 6.0 10.0 15.0] [6.0 13.0 21.0 30.0 40.0]]
- arkouda.array_api.statistical_functions.max(x: arkouda.array_api.array_object.Array, /, *, axis: int | Tuple[int, Ellipsis] | None = None, keepdims: bool = False) arkouda.array_api.array_object.Array[source]¶
Compute the maximum values of an array along a given axis or axes.
- Parameters:
x (Array) – The array to compute the maximum of
axis (int or Tuple[int, ...], optional) – The axis or axes along which to compute the maximum values. If None, the maximum value of the entire array is computed (returning a scalar-array).
keepdims (bool, optional) – Whether to keep the singleton dimension(s) along axis in the result.
- Returns:
An array with the maximum values along the given axis, or a one-element array with the maximum value, if no axis is given.
- Return type:
- Raises:
TypeError – Raised if x is not real numeric.
Examples
>>> import arkouda as ak >>> import arkouda.array_api as xp >>> a = xp.asarray(ak.arange(10,dtype=ak.float64)) >>> xp.max(a) Arkouda Array ((), float64)9.0 >>> a = xp.asarray(ak.arange(10,dtype=ak.float64).reshape(2,5)) >>> xp.max(a,axis=0) Arkouda Array ((5,), float64)[5.0 6.0 7.0 8.0 9.0] >>> xp.max(a,axis=1) Arkouda Array ((2,), float64)[4.0 9.0]
- arkouda.array_api.statistical_functions.mean(x: arkouda.array_api.array_object.Array, /, *, axis: int | Tuple[int, Ellipsis] | None = None, keepdims: bool = False) arkouda.array_api.array_object.Array[source]¶
Compute the minimum values of an array along a given axis or axes.
- Parameters:
x (Array) – The array to compute the minimum of
axis (int or Tuple[int, ...], optional) – The axis or axes along which to compute the mean. If None, the mean of the entire array is computed (returning a scalar-array).
keepdims (bool, optional) – Whether to keep the singleton dimension(s) along axis in the result.
- Returns:
The mean calculated from the pda sum and size, along the axis/axes if those are given.
- Return type:
- Raises:
IndexError – Raised if axis is not valid for the given array.
TypeError – Raised if x is not real numeric.
Examples
>>> import arkouda as ak >>> import arkouda.array_api as xp >>> a = xp.asarray(ak.arange(10,dtype=ak.float64)) >>> xp.mean(a) Arkouda Array ((1,), float64)[4.5] >>> a = xp.asarray(ak.arange(10,dtype=ak.float64).reshape(2,5)) >>> xp.mean(a,axis=0) Arkouda Array ((5,), float64)[2.5 3.5 4.5 5.5 6.5] >>> xp.mean(a,axis=1) Arkouda Array ((2,), float64)[2.0 7.0]
- arkouda.array_api.statistical_functions.mean_shim(x: arkouda.array_api.array_object.Array, axis=None, dtype=None, out=None, keepdims=False)[source]¶
- arkouda.array_api.statistical_functions.min(x: arkouda.array_api.array_object.Array, /, *, axis: int | Tuple[int, Ellipsis] | None = None, keepdims: bool = False) arkouda.array_api.array_object.Array[source]¶
Compute the mean of an array along a given axis or axes.
- Parameters:
x (Array) – The array to compute the mean of
axis (int or Tuple[int, ...], optional) – The axis or axes along which to compute the minimum values. If None, the minimum of the entire array is computed (returning a scalar-array).
keepdims (bool, optional) – Whether to keep the singleton dimension(s) along axis in the result.
- Returns:
An array with the minimum values along the given axis, or a one-element array with the minimum value, if no axis is given.
- Return type:
- Raises:
TypeError – Raised if x is not real numeric.
Examples
>>> import arkouda as ak >>> import arkouda.array_api as xp >>> a = xp.asarray(ak.arange(10,dtype=ak.float64)) >>> xp.min(a) Arkouda Array ((), float64)0.0 >>> a = xp.asarray(ak.arange(10,dtype=ak.float64).reshape(2,5)) >>> xp.min(a,axis=0) Arkouda Array ((5,), float64)[0.0 1.0 2.0 3.0 4.0] >>> xp.min(a,axis=1) Arkouda Array ((2,), float64)[0.0 5.0]
- arkouda.array_api.statistical_functions.prod(x: arkouda.array_api.array_object.Array, /, *, axis: int | Tuple[int, Ellipsis] | None = None, dtype: arkouda.array_api._typing.Dtype | None = None, keepdims: bool = False) arkouda.array_api.array_object.Array[source]¶
Compute the product of an array along a given axis or axes.
- Parameters:
x (Array) – The array to compute the product of
axis (int or Tuple[int, ...], optional) – The axis or axes along which to compute the product. If None, the product of the entire array is computed (returning a scalar-array).
dtype (Dtype, optional) – The dtype of the returned array. If None, the dtype of the input array is used.
keepdims (bool, optional) – Whether to keep the singleton dimension(s) along axis in the result.
- Returns:
An array with the product along the given axis, or a one-element array with the product of the entire array, if no axis is given.
- Return type:
- Raises:
TypeError – Raised if x._array is not real numeric, or can’t be cast to a pdarray.
Examples
>>> import arkouda as ak >>> import arkouda.array_api as xp >>> a = xp.asarray(1 + ak.arange(10,dtype=ak.float64)) >>> xp.prod(a) Arkouda Array ((), float64)3628800.0 >>> a = xp.asarray((1 + ak.arange(10,dtype=ak.float64)).reshape(2,5)) >>> xp.prod(a,axis=0) Arkouda Array ((5,), float64)[6.0 14.0 24.0 36.0 50.0] >>> xp.prod(a,axis=1) Arkouda Array ((2,), float64)[120.0 30240.0]
- arkouda.array_api.statistical_functions.std(x: arkouda.array_api.array_object.Array, /, *, axis: int | Tuple[int, Ellipsis] | None = None, correction: int | float = 0.0, keepdims: bool = False) arkouda.array_api.array_object.Array[source]¶
Compute the standard deviation of an array along a given axis or axes.
- Parameters:
x (Array) – The array to compute the standard deviation of
axis (int or Tuple[int, ...], optional) – The axis or axes along which to compute the standard deviation. If None, the standard deviation of the entire array is computed (returning a scalar-array).
correction (int or float, optional) – The degrees of freedom correction to apply. The default is 0.
keepdims (bool, optional) – Whether to keep the singleton dimension(s) along axis in the result.
- Returns:
An array with the standard deviation along the given axis, or a one-element array with the std of the entire array, if no axis is given.
- Return type:
- Raises:
TypeError – Raised if x is not floating point.
ValueError – Raised if correction is negative.
IndexError – Raised if axis is not valid for given Array.
Examples
>>> import arkouda as ak >>> import arkouda.array_api as xp >>> a = xp.asarray((1 + ak.arange(10,dtype=ak.float64))) >>> xp.std(a) Arkouda Array ((1,), float64)[2.87228] >>> a = xp.asarray((1 + ak.arange(10,dtype=ak.float64)).reshape(2,5)) >>> xp.std(a,axis=0) Arkouda Array ((5,), float64)[2.5 2.5 2.5 2.5 2.5] >>> xp.std(a,axis=1) Arkouda Array ((2,), float64)[1.41421 1.41421]
- arkouda.array_api.statistical_functions.sum(x: arkouda.array_api.array_object.Array, /, *, axis: int | Tuple[int, Ellipsis] | None = None, dtype: arkouda.array_api._typing.Dtype | None = None, keepdims: bool = False) arkouda.array_api.array_object.Array[source]¶
Compute the sum of an array along a given axis or axes.
- Parameters:
x (Array) – The array to compute the sum of
axis (int or Tuple[int, ...], optional) – The axis or axes along which to compute the sum. If None, the sum of the entire array is computed (returning a scalar-array).
dtype (Dtype, optional) – The dtype of the returned array. If None, the dtype of the input array is used.
keepdims (bool, optional) – Whether to keep the singleton dimension(s) along axis in the result.
- Returns:
An array with the sum along the given axis, or a one-element array with the sum of the entire array, if no axis is given.
- Return type:
- Raises:
TypeError – Raised if x is not numeric.
Examples
>>> import arkouda as ak >>> import arkouda.array_api as xp >>> a = xp.asarray(1 + ak.arange(10,dtype=ak.float64)) >>> xp.sum(a) Arkouda Array ((), float64)55.0 >>> a = xp.asarray((1 + ak.arange(10,dtype=ak.float64)).reshape(2,5)) >>> xp.sum(a,axis=0) Arkouda Array ((5,), float64)[7.0 9.0 11.0 13.0 15.0] >>> xp.sum(a,axis=1) Arkouda Array ((2,), float64)[15.0 40.0]
- arkouda.array_api.statistical_functions.var(x: arkouda.array_api.array_object.Array, /, *, axis: int | Tuple[int, Ellipsis] | None = None, correction: int | float = 0.0, keepdims: bool = False) arkouda.array_api.array_object.Array[source]¶
Compute the variance of an array along a given axis or axes.
- Parameters:
x (Array) – The array to compute the variance of
axis (int or Tuple[int, ...], optional) – The axis or axes along which to compute the variance. If None, the variance of the entire array is computed (returning a scalar-array).
correction (int or float, optional) – The degrees of freedom correction to apply. The default is 0.
keepdims (bool, optional) – Whether to keep the singleton dimension(s) along axis in the result.
- Returns:
An array with the variance along the given axis, or a one-element array with the var of the entire array, if no axis is given.
- Return type:
- Raises:
TypeError – Raised if x is not floating point.
ValueError – Raised if correction is negative.
IndexError – Raised if axis is not valid for given Array.
Examples
>>> import arkouda as ak >>> import arkouda.array_api as xp >>> a = xp.asarray((1 + ak.arange(10,dtype=ak.float64))) >>> xp.var(a) Arkouda Array ((1,), float64)[8.25] >>> a = xp.asarray((1 + ak.arange(10,dtype=ak.float64)).reshape(2,5)) >>> xp.var(a,axis=0) Arkouda Array ((5,), float64)[6.25 6.25 6.25 6.25 6.25] >>> xp.var(a,axis=1) Arkouda Array ((2,), float64)[2.0 2.0]