arkouda.numeric

Module Contents

Classes

ErrorMode

Generic enumeration.

Functions

abs(→ arkouda.pdarrayclass.pdarray)

Return the element-wise absolute value of the array.

arccos(→ arkouda.pdarrayclass.pdarray)

Return the element-wise inverse cosine of the array. The result is between 0 and pi.

arccosh(→ arkouda.pdarrayclass.pdarray)

Return the element-wise inverse hyperbolic cosine of the array.

arcsin(→ arkouda.pdarrayclass.pdarray)

Return the element-wise inverse sine of the array. The result is between -pi/2 and pi/2.

arcsinh(→ arkouda.pdarrayclass.pdarray)

Return the element-wise inverse hyperbolic sine of the array.

arctan(→ arkouda.pdarrayclass.pdarray)

Return the element-wise inverse tangent of the array. The result is between -pi/2 and pi/2.

arctan2(→ arkouda.pdarrayclass.pdarray)

Return the element-wise inverse tangent of the array pair. The result chosen is the

arctanh(→ arkouda.pdarrayclass.pdarray)

Return the element-wise inverse hyperbolic tangent of the array.

cast(→ Union[Union[arkouda.pdarrayclass.pdarray, ...)

Cast an array to another dtype.

ceil(→ arkouda.pdarrayclass.pdarray)

Return the element-wise ceiling of the array.

clip(→ arkouda.pdarrayclass.pdarray)

Clip (limit) the values in an array to a given range [lo,hi]

cos(→ arkouda.pdarrayclass.pdarray)

Return the element-wise cosine of the array.

cosh(→ arkouda.pdarrayclass.pdarray)

Return the element-wise hyperbolic cosine of the array.

cumprod(→ arkouda.pdarrayclass.pdarray)

Return the cumulative product over the array.

cumsum(→ arkouda.pdarrayclass.pdarray)

Return the cumulative sum over the array.

deg2rad(→ arkouda.pdarrayclass.pdarray)

Converts angles element-wise from degrees to radians.

exp(→ arkouda.pdarrayclass.pdarray)

Return the element-wise exponential of the array.

expm1(→ arkouda.pdarrayclass.pdarray)

Return the element-wise exponential of the array minus one.

floor(→ arkouda.pdarrayclass.pdarray)

Return the element-wise floor of the array.

hash(→ Union[Tuple[arkouda.pdarrayclass.pdarray, ...)

Return an element-wise hash of the array or list of arrays.

histogram(→ Tuple[arkouda.pdarrayclass.pdarray, ...)

Compute a histogram of evenly spaced bins over the range of an array.

histogram2d(→ Tuple[arkouda.pdarrayclass.pdarray, ...)

Compute the bi-dimensional histogram of two data samples with evenly spaced bins

histogramdd(→ Tuple[arkouda.pdarrayclass.pdarray, ...)

Compute the multidimensional histogram of data in sample with evenly spaced bins.

isfinite(→ arkouda.pdarrayclass.pdarray)

Return the element-wise isfinite check applied to the array.

isinf(→ arkouda.pdarrayclass.pdarray)

Return the element-wise isinf check applied to the array.

isnan(→ arkouda.pdarrayclass.pdarray)

Return the element-wise isnan check applied to the array.

log(→ arkouda.pdarrayclass.pdarray)

Return the element-wise natural log of the array.

log10(→ arkouda.pdarrayclass.pdarray)

Return the element-wise base 10 log of the array.

log1p(→ arkouda.pdarrayclass.pdarray)

Return the element-wise natural log of one plus the array.

log2(→ arkouda.pdarrayclass.pdarray)

Return the element-wise base 2 log of the array.

rad2deg(→ arkouda.pdarrayclass.pdarray)

Converts angles element-wise from radians to degrees.

round(→ arkouda.pdarrayclass.pdarray)

Return the element-wise rounding of the array.

sign(→ arkouda.pdarrayclass.pdarray)

Return the element-wise sign of the array.

sin(→ arkouda.pdarrayclass.pdarray)

Return the element-wise sine of the array.

sinh(→ arkouda.pdarrayclass.pdarray)

Return the element-wise hyperbolic sine of the array.

square(→ arkouda.pdarrayclass.pdarray)

Return the element-wise square of the array.

tan(→ arkouda.pdarrayclass.pdarray)

Return the element-wise tangent of the array.

tanh(→ arkouda.pdarrayclass.pdarray)

Return the element-wise hyperbolic tangent of the array.

trunc(→ arkouda.pdarrayclass.pdarray)

Return the element-wise truncation of the array.

value_counts(→ Union[Categorical, ...)

Count the occurrences of the unique values of an array.

where(→ Union[arkouda.pdarrayclass.pdarray, ...)

Returns an array with elements chosen from A and B based upon a

class arkouda.numeric.ErrorMode[source]

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

ignore = 'ignore'
return_validity = 'return_validity'
strict = 'strict'
arkouda.numeric.abs(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise absolute value of the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing absolute values of the input array elements

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> ak.abs(ak.arange(-5,-1))
array([5, 4, 3, 2])
>>> ak.abs(ak.linspace(-5,-1,5))
array([5, 4, 3, 2, 1])
arkouda.numeric.arccos(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise inverse cosine of the array. The result is between 0 and pi.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the inverse cosine will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing inverse cosine for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.arccosh(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise inverse hyperbolic cosine of the array.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the inverse hyperbolic cosine will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing inverse hyperbolic cosine for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.arcsin(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise inverse sine of the array. The result is between -pi/2 and pi/2.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the inverse sine will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing inverse sine for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.arcsinh(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise inverse hyperbolic sine of the array.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the inverse hyperbolic sine will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing inverse hyperbolic sine for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.arctan(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise inverse tangent of the array. The result is between -pi/2 and pi/2.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the inverse tangent will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing inverse tangent for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.arctan2(num: arkouda.pdarrayclass.pdarray | arkouda.dtypes.numeric_scalars, denom: arkouda.pdarrayclass.pdarray | arkouda.dtypes.numeric_scalars, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise inverse tangent of the array pair. The result chosen is the signed angle in radians between the ray ending at the origin and passing through the point (1,0), and the ray ending at the origin and passing through the point (denom, num). The result is between -pi and pi.

Parameters:
  • num (Union[numeric_scalars, pdarray]) – Numerator of the arctan2 argument.

  • denom (Union[numeric_scalars, pdarray]) – Denominator of the arctan2 argument.

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the inverse tangent will be applied to the corresponding values. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing inverse tangent for each corresponding element pair of the original pdarray, using the signed values or the numerator and denominator to get proper placement on unit circle.

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.arctanh(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise inverse hyperbolic tangent of the array.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the inverse hyperbolic tangent will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing inverse hyperbolic tangent for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameters are not a pdarray or numeric scalar.

arkouda.numeric.cast(pda: arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical, dt: numpy.dtype | type | str | arkouda.dtypes.BigInt, errors: ErrorMode = ErrorMode.strict) arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical | Tuple[arkouda.pdarrayclass.pdarray, arkouda.pdarrayclass.pdarray][source]

Cast an array to another dtype.

Parameters:
  • pda (pdarray or Strings) – The array of values to cast

  • dt (np.dtype, type, or str) – The target dtype to cast values to

  • errors ({strict, ignore, return_validity}) –

    Controls how errors are handled when casting strings to a numeric type (ignored for casts from numeric types).

    • strict: raise RuntimeError if any string cannot be converted

    • ignore: never raise an error. Uninterpretable strings get

      converted to NaN (float64), -2**63 (int64), zero (uint64 and uint8), or False (bool)

    • return_validity: in addition to returning the same output as “ignore”, also return a bool array indicating where the cast was successful.

Returns:

  • pdarray or Strings – Array of values cast to desired dtype

  • [validity (pdarray(bool)]) – If errors=”return_validity” and input is Strings, a second array is returned with True where the cast succeeded and False where it failed.

Notes

The cast is performed according to Chapel’s casting rules and is NOT safe from overflows or underflows. The user must ensure that the target dtype has the precision and capacity to hold the desired result.

Examples

>>> ak.cast(ak.linspace(1.0,5.0,5), dt=ak.int64)
array([1, 2, 3, 4, 5])
>>> ak.cast(ak.arange(0,5), dt=ak.float64).dtype
dtype('float64')
>>> ak.cast(ak.arange(0,5), dt=ak.bool)
array([False, True, True, True, True])
>>> ak.cast(ak.linspace(0,4,5), dt=ak.bool)
array([False, True, True, True, True])
arkouda.numeric.ceil(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise ceiling of the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing ceiling values of the input array elements

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> ak.ceil(ak.linspace(1.1,5.5,5))
array([2, 3, 4, 5, 6])
arkouda.numeric.clip(pda: arkouda.pdarrayclass.pdarray, lo: arkouda.dtypes.numeric_scalars | arkouda.pdarrayclass.pdarray, hi: arkouda.dtypes.numeric_scalars | arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Clip (limit) the values in an array to a given range [lo,hi]

Given an array a, values outside the range are clipped to the range edges, such that all elements lie in the range.

There is no check to enforce that lo < hi. If lo > hi, the corresponding value of the array will be set to hi.

If lo or hi (or both) are pdarrays, the check is by pairwise elements. See examples.

Parameters:
  • pda (pdarray, int64 or float64) – the array of values to clip

  • lo (scalar or pdarray, int64 or float64) – the lower value of the clipping range

  • hi (scalar or pdarray, int64 or float64) – the higher value of the clipping range

  • pdarrays (If lo or hi (or both) are) – See examples.

  • elements. (the check is by pairwise) – See examples.

Returns:

A pdarray matching pda, except that element x remains x if lo <= x <= hi,

or becomes lo if x < lo, or becomes hi if x > hi.

Return type:

arkouda.pdarrayclass.pdarray

Examples

>>> a = ak.array([1,2,3,4,5,6,7,8,9,10])
>>> ak.clip(a,3,8)
array([3,3,3,4,5,6,7,8,8,8])
>>> ak.clip(a,3,8.0)
array([3.00000000000000000 3.00000000000000000 3.00000000000000000 4.00000000000000000
       5.00000000000000000 6.00000000000000000 7.00000000000000000 8.00000000000000000
       8.00000000000000000 8.00000000000000000])
>>> ak.clip(a,None,7)
array([1,2,3,4,5,6,7,7,7,7])
>>> ak.clip(a,5,None)
array([5,5,5,5,5,6,7,8,9,10])
>>> ak.clip(a,None,None)
ValueError : either min or max must be supplied
>>> ak.clip(a,ak.array([2,2,3,3,8,8,5,5,6,6],8))
array([2,2,3,4,8,8,7,8,8,8])
>>> ak.clip(a,4,ak.array([10,9,8,7,6,5,5,5,5,5]))
array([4,4,4,4,5,5,5,5,5,5])

Notes

Either lo or hi may be None, but not both. If lo > hi, all x = hi. If all inputs are int64, output is int64, but if any input is float64, output is float64.

Raises:

ValueError – Raised if both lo and hi are None

arkouda.numeric.cos(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise cosine of the array.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the cosine will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing cosine for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.cosh(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise hyperbolic cosine of the array.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the hyperbolic cosine will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing hyperbolic cosine for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.cumprod(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the cumulative product over the array.

The product is inclusive, such that the i th element of the result is the product of elements up to and including i.

Parameters:

pda (pdarray)

Returns:

A pdarray containing cumulative products for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> ak.cumprod(ak.arange(1,5))
array([1, 2, 6, 24]))
>>> ak.cumprod(ak.uniform(5,1.0,5.0))
array([1.5728783400481925, 7.0472855509390593, 33.78523998586553,
       134.05309592737584, 450.21589865655358])
arkouda.numeric.cumsum(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the cumulative sum over the array.

The sum is inclusive, such that the i th element of the result is the sum of elements up to and including i.

Parameters:

pda (pdarray)

Returns:

A pdarray containing cumulative sums for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> ak.cumsum(ak.arange([1,5]))
array([1, 3, 6])
>>> ak.cumsum(ak.uniform(5,1.0,5.0))
array([3.1598310770203937, 5.4110385860243131, 9.1622479306453748,
       12.710615785506533, 13.945880905466208])
>>> ak.cumsum(ak.randint(0, 1, 5, dtype=ak.bool))
array([0, 1, 1, 2, 3])
arkouda.numeric.deg2rad(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Converts angles element-wise from degrees to radians.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the corresponding value will be converted from degrees to radians. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing an angle converted to radians, from degrees, for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.exp(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise exponential of the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing exponential values of the input array elements

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> ak.exp(ak.arange(1,5))
array([2.7182818284590451, 7.3890560989306504, 20.085536923187668, 54.598150033144236])
>>> ak.exp(ak.uniform(5,1.0,5.0))
array([11.84010843172504, 46.454368507659211, 5.5571769623557188,
       33.494295836924771, 13.478894913238722])
arkouda.numeric.expm1(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise exponential of the array minus one.

Parameters:

pda (pdarray)

Returns:

A pdarray containing exponential values of the input array elements minus one

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> ak.exp1m(ak.arange(1,5))
array([1.7182818284590451, 6.3890560989306504, 19.085536923187668, 53.598150033144236])
>>> ak.exp1m(ak.uniform(5,1.0,5.0))
array([10.84010843172504, 45.454368507659211, 4.5571769623557188,
       32.494295836924771, 12.478894913238722])
arkouda.numeric.floor(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise floor of the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing floor values of the input array elements

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> ak.floor(ak.linspace(1.1,5.5,5))
array([1, 2, 3, 4, 5])
arkouda.numeric.hash(pda: arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | SegArray | Categorical | List[arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | SegArray | Categorical], full: bool = True) Tuple[arkouda.pdarrayclass.pdarray, arkouda.pdarrayclass.pdarray] | arkouda.pdarrayclass.pdarray[source]

Return an element-wise hash of the array or list of arrays.

Parameters:
  • pda (Union[pdarray, Strings, Segarray, Categorical],) – List[Union[pdarray, Strings, Segarray, Categorical]]]

  • full (bool) – This is only used when a single pdarray is passed into hash By default, a 128-bit hash is computed and returned as two int64 arrays. If full=False, then a 64-bit hash is computed and returned as a single int64 array.

Returns:

If full=True or a list of pdarrays is passed, a 2-tuple of pdarrays containing the high and low 64 bits of each hash, respectively. If full=False and a single pdarray is passed, a single pdarray containing a 64-bit hash

Return type:

hashes

Raises:

TypeError – Raised if the parameter is not a pdarray

Notes

In the case of a single pdarray being passed, this function uses the SIPhash algorithm, which can output either a 64-bit or 128-bit hash. However, the 64-bit hash runs a significant risk of collisions when applied to more than a few million unique values. Unless the number of unique values is known to be small, the 128-bit hash is strongly recommended.

Note that this hash should not be used for security, or for any cryptographic application. Not only is SIPhash not intended for such uses, but this implementation employs a fixed key for the hash, which makes it possible for an adversary with control over input to engineer collisions.

In the case of a list of pdrrays, Strings, Categoricals, or Segarrays being passed, a non-linear function must be applied to each array since hashes of subsequent arrays cannot be simply XORed because equivalent values will cancel each other out, hence we do a rotation by the ordinal of the array.

arkouda.numeric.histogram(pda: arkouda.pdarrayclass.pdarray, bins: arkouda.dtypes.int_scalars = 10) Tuple[arkouda.pdarrayclass.pdarray, arkouda.pdarrayclass.pdarray][source]

Compute a histogram of evenly spaced bins over the range of an array.

Parameters:
  • pda (pdarray) – The values to histogram

  • bins (int_scalars) – The number of equal-size bins to use (default: 10)

Returns:

Bin edges and The number of values present in each bin

Return type:

(pdarray, Union[pdarray, int64 or float64])

Raises:
  • TypeError – Raised if the parameter is not a pdarray or if bins is not an int.

  • ValueError – Raised if bins < 1

  • NotImplementedError – Raised if pdarray dtype is bool or uint8

Notes

The bins are evenly spaced in the interval [pda.min(), pda.max()].

Examples

>>> import matplotlib.pyplot as plt
>>> A = ak.arange(0, 10, 1)
>>> nbins = 3
>>> h, b = ak.histogram(A, bins=nbins)
>>> h
array([3, 3, 4])
>>> b
array([0., 3., 6., 9.])

# To plot, export the left edges and the histogram to NumPy >>> plt.plot(b.to_ndarray()[::-1], h.to_ndarray())

arkouda.numeric.histogram2d(x: arkouda.pdarrayclass.pdarray, y: arkouda.pdarrayclass.pdarray, bins: arkouda.dtypes.int_scalars | Sequence[arkouda.dtypes.int_scalars] = 10) Tuple[arkouda.pdarrayclass.pdarray, arkouda.pdarrayclass.pdarray, arkouda.pdarrayclass.pdarray][source]

Compute the bi-dimensional histogram of two data samples with evenly spaced bins

Parameters:
  • x (pdarray) – A pdarray containing the x coordinates of the points to be histogrammed.

  • y (pdarray) – A pdarray containing the y coordinates of the points to be histogrammed.

  • bins (int_scalars or [int, int] = 10) – The number of equal-size bins to use. If int, the number of bins for the two dimensions (nx=ny=bins). If [int, int], the number of bins in each dimension (nx, ny = bins). Defaults to 10

Returns:

  • hist (ArrayView, shape(nx, ny)) – The bi-dimensional histogram of samples x and y. Values in x are histogrammed along the first dimension and values in y are histogrammed along the second dimension.

  • x_edges (pdarray) – The bin edges along the first dimension.

  • y_edges (pdarray) – The bin edges along the second dimension.

Raises:
  • TypeError – Raised if x or y parameters are not pdarrays or if bins is not an int or (int, int).

  • ValueError – Raised if bins < 1

  • NotImplementedError – Raised if pdarray dtype is bool or uint8

See also

histogram

Notes

The x bins are evenly spaced in the interval [x.min(), x.max()] and y bins are evenly spaced in the interval [y.min(), y.max()].

Examples

>>> x = ak.arange(0, 10, 1)
>>> y = ak.arange(9, -1, -1)
>>> nbins = 3
>>> h, x_edges, y_edges = ak.histogram2d(x, y, bins=nbins)
>>> h
array([[0, 0, 3],
       [0, 2, 1],
       [3, 1, 0]])
>>> x_edges
array([0.0 3.0 6.0 9.0])
>>> x_edges
array([0.0 3.0 6.0 9.0])
arkouda.numeric.histogramdd(sample: Sequence[arkouda.pdarrayclass.pdarray], bins: arkouda.dtypes.int_scalars | Sequence[arkouda.dtypes.int_scalars] = 10) Tuple[arkouda.pdarrayclass.pdarray, Sequence[arkouda.pdarrayclass.pdarray]][source]

Compute the multidimensional histogram of data in sample with evenly spaced bins.

Parameters:
  • sample (Sequence[pdarray]) – A sequence of pdarrays containing the coordinates of the points to be histogrammed.

  • bins (int_scalars or Sequence[int_scalars] = 10) – The number of equal-size bins to use. If int, the number of bins for all dimensions (nx=ny=…=bins). If [int, int, …], the number of bins in each dimension (nx, ny, … = bins). Defaults to 10

Returns:

  • hist (ArrayView, shape(nx, ny, …, nd)) – The multidimensional histogram of pdarrays in sample. Values in first pdarray are histogrammed along the first dimension. Values in second pdarray are histogrammed along the second dimension and so on.

  • edges (List[pdarray]) – A list of pdarrays containing the bin edges for each dimension.

Raises:
  • ValueError – Raised if bins < 1

  • NotImplementedError – Raised if pdarray dtype is bool or uint8

See also

histogram

Notes

The bins for each dimension, m, are evenly spaced in the interval [m.min(), m.max()]

Examples

>>> x = ak.arange(0, 10, 1)
>>> y = ak.arange(9, -1, -1)
>>> z = ak.where(x % 2 == 0, x, y)
>>> h, edges = ak.histogramdd((x, y,z), bins=(2,2,5))
>>> h
array([[[0, 0, 0, 0, 0],
        [1, 1, 1, 1, 1]],
[[1, 1, 1, 1, 1],

[0, 0, 0, 0, 0]]])

>>> edges
[array([0.0 4.5 9.0]),
 array([0.0 4.5 9.0]),
 array([0.0 1.6 3.2 4.8 6.4 8.0])]
arkouda.numeric.isfinite(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise isfinite check applied to the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing boolean values indicating whether the input array elements are finite

Return type:

pdarray

Raises:
  • TypeError – Raised if the parameter is not a pdarray

  • RuntimeError – if the underlying pdarray is not float-based

Examples

>>> ak.isfinite(ak.array[1.0, 2.0, ak.inf])
array([True, True, False])
arkouda.numeric.isinf(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise isinf check applied to the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing boolean values indicating whether the input array elements are infinite

Return type:

pdarray

Raises:
  • TypeError – Raised if the parameter is not a pdarray

  • RuntimeError – if the underlying pdarray is not float-based

Examples

>>> ak.isinf(ak.array[1.0, 2.0, ak.inf])
array([False, False, True])
arkouda.numeric.isnan(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise isnan check applied to the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing boolean values indicating whether the input array elements are NaN

Return type:

pdarray

Raises:
  • TypeError – Raised if the parameter is not a pdarray

  • RuntimeError – if the underlying pdarray is not float-based

Examples

>>> ak.isnan(ak.array[1.0, 2.0, 1.0 / 0.0])
array([False, False, True])
arkouda.numeric.log(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise natural log of the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing natural log values of the input array elements

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Notes

Logarithms with other bases can be computed as follows:

Examples

>>> A = ak.array([1, 10, 100])
# Natural log
>>> ak.log(A)
array([0, 2.3025850929940459, 4.6051701859880918])
# Log base 10
>>> ak.log(A) / np.log(10)
array([0, 1, 2])
# Log base 2
>>> ak.log(A) / np.log(2)
array([0, 3.3219280948873626, 6.6438561897747253])
arkouda.numeric.log10(x: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise base 10 log of the array.

Parameters:

x (pdarray) – array to compute on

Return type:

pdarray contain values of the base 10 log

arkouda.numeric.log1p(x: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise natural log of one plus the array.

Parameters:

x (pdarray) – array to compute on

Return type:

pdarray contain values of the natural log of one plus the array

arkouda.numeric.log2(x: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise base 2 log of the array.

Parameters:

x (pdarray) – array to compute on

Return type:

pdarray contain values of the base 2 log

arkouda.numeric.rad2deg(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Converts angles element-wise from radians to degrees.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the corresponding value will be converted from radians to degrees. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing an angle converted to degrees, from radians, for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.round(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise rounding of the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing input array elements rounded to the nearest integer

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> ak.round(ak.array([1.1, 2.5, 3.14159]))
array([1, 3, 3])
arkouda.numeric.sign(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise sign of the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing sign values of the input array elements

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> ak.sign(ak.array([-10, -5, 0, 5, 10]))
array([-1, -1, 0, 1, 1])
arkouda.numeric.sin(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise sine of the array.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the sine will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing sin for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.sinh(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise hyperbolic sine of the array.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the hyperbolic sine will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing hyperbolic sine for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.square(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise square of the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing square values of the input array elements

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> ak.square(ak.arange(1,5))
array([1, 4, 9, 16])
arkouda.numeric.tan(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise tangent of the array.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the tangent will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing tangent for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.tanh(pda: arkouda.pdarrayclass.pdarray, where: bool | arkouda.pdarrayclass.pdarray = True) arkouda.pdarrayclass.pdarray[source]

Return the element-wise hyperbolic tangent of the array.

Parameters:
  • pda (pdarray)

  • where (Boolean or pdarray) – This condition is broadcast over the input. At locations where the condition is True, the hyperbolic tangent will be applied to the corresponding value. Elsewhere, it will retain its original value. Default set to True.

Returns:

A pdarray containing hyperbolic tangent for each element of the original pdarray

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

arkouda.numeric.trunc(pda: arkouda.pdarrayclass.pdarray) arkouda.pdarrayclass.pdarray[source]

Return the element-wise truncation of the array.

Parameters:

pda (pdarray)

Returns:

A pdarray containing input array elements truncated to the nearest integer

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> ak.trunc(ak.array([1.1, 2.5, 3.14159]))
array([1, 2, 3])
arkouda.numeric.value_counts(pda: arkouda.pdarrayclass.pdarray) Categorical | Tuple[arkouda.pdarrayclass.pdarray | arkouda.strings.Strings, arkouda.pdarrayclass.pdarray | None][source]

Count the occurrences of the unique values of an array.

Parameters:

pda (pdarray, int64) – The array of values to count

Returns:

  • unique_values (pdarray, int64 or Strings) – The unique values, sorted in ascending order

  • counts (pdarray, int64) – The number of times the corresponding unique value occurs

Raises:

TypeError – Raised if the parameter is not a pdarray

See also

unique, histogram

Notes

This function differs from histogram() in that it only returns counts for values that are present, leaving out empty “bins”. This function delegates all logic to the unique() method where the return_counts parameter is set to True.

Examples

>>> A = ak.array([2, 0, 2, 4, 0, 0])
>>> ak.value_counts(A)
(array([0, 2, 4]), array([3, 2, 1]))
arkouda.numeric.where(condition: arkouda.pdarrayclass.pdarray, A: str | arkouda.dtypes.numeric_scalars | arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical, B: str | arkouda.dtypes.numeric_scalars | arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical) arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical[source]

Returns an array with elements chosen from A and B based upon a conditioning array. As is the case with numpy.where, the return array consists of values from the first array (A) where the conditioning array elements are True and from the second array (B) where the conditioning array elements are False.

Parameters:
Returns:

Values chosen from A where the condition is True and B where the condition is False

Return type:

pdarray

Raises:
  • TypeError – Raised if the condition object is not a pdarray, if A or B is not an int, np.int64, float, np.float64, pdarray, str, Strings, Categorical if pdarray dtypes are not supported or do not match, or multiple condition clauses (see Notes section) are applied

  • ValueError – Raised if the shapes of the condition, A, and B pdarrays are unequal

Examples

>>> a1 = ak.arange(1,10)
>>> a2 = ak.ones(9, dtype=np.int64)
>>> cond = a1 < 5
>>> ak.where(cond,a1,a2)
array([1, 2, 3, 4, 1, 1, 1, 1, 1])
>>> a1 = ak.arange(1,10)
>>> a2 = ak.ones(9, dtype=np.int64)
>>> cond = a1 == 5
>>> ak.where(cond,a1,a2)
array([1, 1, 1, 1, 5, 1, 1, 1, 1])
>>> a1 = ak.arange(1,10)
>>> a2 = 10
>>> cond = a1 < 5
>>> ak.where(cond,a1,a2)
array([1, 2, 3, 4, 10, 10, 10, 10, 10])
>>> s1 = ak.array([f'str {i}' for i in range(10)])
>>> s2 = 'str 21'
>>> cond = (ak.arange(10) % 2 == 0)
>>> ak.where(cond,s1,s2)
array(['str 0', 'str 21', 'str 2', 'str 21', 'str 4', 'str 21', 'str 6', 'str 21', 'str 8','str 21'])
>>> c1 = ak.Categorical(ak.array([f'str {i}' for i in range(10)]))
>>> c2 = ak.Categorical(ak.array([f'str {i}' for i in range(9, -1, -1)]))
>>> cond = (ak.arange(10) % 2 == 0)
>>> ak.where(cond,c1,c2)
array(['str 0', 'str 8', 'str 2', 'str 6', 'str 4', 'str 4', 'str 6', 'str 2', 'str 8', 'str 0'])

Notes

A and B must have the same dtype and only one conditional clause is supported e.g., n < 5, n > 1, which is supported in numpy is not currently supported in Arkouda