arkouda.numpy.numeric

Classes

ErrorMode

Create a collection of name/value pairs.

Functions

abs(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise absolute value of the array.

arccos(→ arkouda.numpy.pdarrayclass.pdarray)

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

arccosh(→ arkouda.numpy.pdarrayclass.pdarray)

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

arcsin(→ arkouda.numpy.pdarrayclass.pdarray)

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

arcsinh(→ arkouda.numpy.pdarrayclass.pdarray)

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

arctan(→ arkouda.numpy.pdarrayclass.pdarray)

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

arctan2(→ arkouda.numpy.pdarrayclass.pdarray)

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

arctanh(→ arkouda.numpy.pdarrayclass.pdarray)

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

array_equal(→ bool)

Compares two pdarrays for equality.

cast(…)

Cast an array to another dtype.

ceil(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise ceiling of the array.

clip(→ arkouda.numpy.pdarrayclass.pdarray)

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

cos(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise cosine of the array.

cosh(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise hyperbolic cosine of the array.

count_nonzero(→ arkouda.numpy.dtypes.int_scalars)

Compute the nonzero count of a given array. 1D case only, for now.

cumprod(→ arkouda.numpy.pdarrayclass.pdarray)

Return the cumulative product over the array.

cumsum(→ arkouda.numpy.pdarrayclass.pdarray)

Return the cumulative sum over the array.

deg2rad(→ arkouda.numpy.pdarrayclass.pdarray)

Converts angles element-wise from degrees to radians.

exp(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise exponential of the array.

expm1(→ arkouda.numpy.pdarrayclass.pdarray)

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

eye(→ arkouda.numpy.pdarrayclass.pdarray)

Return a pdarray with zeros everywhere except along a diagonal, which is all ones.

fabs(→ arkouda.numpy.pdarrayclass.pdarray)

Compute the absolute values element-wise, casting to a float beforehand.

floor(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise floor of the array.

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

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

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

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

histogram2d(...)

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

histogramdd(...)

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

isfinite(→ arkouda.numpy.pdarrayclass.pdarray)

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

isinf(→ arkouda.numpy.pdarrayclass.pdarray)

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

isnan(→ arkouda.numpy.pdarrayclass.pdarray)

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

log(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise natural log of the array.

log10(→ arkouda.numpy.pdarrayclass.pdarray)

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

log1p(→ arkouda.numpy.pdarrayclass.pdarray)

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

log2(→ arkouda.numpy.pdarrayclass.pdarray)

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

matmul(→ arkouda.numpy.pdarrayclass.pdarray)

Compute the product of two matrices.

median(→ numpy.float64)

Compute the median of a given array. 1d case only, for now.

nextafter(→ Union[arkouda.numpy.pdarrayclass.pdarray, ...)

Return the next floating-point value after x1 towards x2, element-wise.

percentile(...)

Compute the q-th percentile of the data along the specified axis.

putmask(→ None)

Overwrite elements of A with elements from B based upon a mask array.

quantile(→ Union[arkouda.numpy.dtypes.numeric_scalars, ...)

Compute the q-th quantile of the data along the specified axis.

rad2deg(→ arkouda.numpy.pdarrayclass.pdarray)

Converts angles element-wise from radians to degrees.

round(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise rounding of the array.

sign(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise sign of the array.

sin(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise sine of the array.

sinh(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise hyperbolic sine of the array.

square(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise square of the array.

take(→ arkouda.numpy.pdarrayclass.pdarray)

Take elements from an array along an axis.

tan(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise tangent of the array.

tanh(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise hyperbolic tangent of the array.

transpose(→ arkouda.numpy.pdarrayclass.pdarray)

Compute the transpose of a matrix.

tril(→ arkouda.numpy.pdarrayclass.pdarray)

Return a copy of the pda with the upper triangle zeroed out.

triu(→ arkouda.numpy.pdarrayclass.pdarray)

Return a copy of the pda with the lower triangle zeroed out.

trunc(→ arkouda.numpy.pdarrayclass.pdarray)

Return the element-wise truncation of the array.

value_counts(→ tuple[arkouda.groupbyclass.groupable, ...)

Count the occurrences of the unique values of an array.

vecdot(→ Union[arkouda.numpy.dtypes.numeric_scalars, ...)

Computes the numpy-style vecdot product of two matrices. This differs from the

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

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

Module Contents

class arkouda.numpy.numeric.ErrorMode(*args, **kwds)[source]

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

ignore = 'ignore'
return_validity = 'return_validity'
strict = 'strict'
arkouda.numpy.numeric.abs(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.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

>>> import arkouda as ak
>>> ak.abs(ak.arange(-5,-1))
array([5 4 3 2])
>>> ak.abs(ak.linspace(-5,-1,5))
array([5.00000000... 4.00000000... 3.00000000...
2.00000000... 1.00000000...])
arkouda.numpy.numeric.arccos(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

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

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(-0.7,0.5,4)
>>> ak.arccos(a)
array([2.34619382... 1.87548898... 1.47062890... 1.04719755...])
arkouda.numpy.numeric.arccosh(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

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

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(1,500,4)
>>> ak.arccosh(a)
array([0.00000000... 5.81312608... 6.50328742... 6.90775427...])
arkouda.numpy.numeric.arcsin(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.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 (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(-0.7,0.5,4)
>>> ak.arcsin(a)
array([-0.77539749... -0.30469265... 0.10016742... 0.52359877...])
arkouda.numpy.numeric.arcsinh(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

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

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(-500,500,4)
>>> ak.arcsinh(a)
array([-6.90775627... -5.80915199... 5.80915199... 6.90775627...])
arkouda.numpy.numeric.arctan(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.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 (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(-10.7,10.5,4)
>>> ak.arctan(a)
array([-1.47760906... -1.30221689... 1.28737507... 1.47584462...])
arkouda.numpy.numeric.arctan2(num: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.dtypes.numeric_scalars, denom: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.dtypes.numeric_scalars, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.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 (pdarray or numeric_scalars) – Numerator of the arctan2 argument.

  • denom (pdarray or numeric_scalars) – Denominator of the arctan2 argument.

  • where (bool or pdarray, default=True) – 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 any parameter fails the typechecking
Raised if any element of pdarrays num and denom is not a supported type
Raised if both num and denom are scalars
Raised if where is neither boolean nor a pdarray of boolean

Examples

>>> import arkouda as ak
>>> x = ak.array([1,-1,-1,1])
>>> y = ak.array([1,1,-1,-1])
>>> ak.arctan2(y,x)
array([0.78539816... 2.35619449... -2.35619449... -0.78539816...])
arkouda.numpy.numeric.arctanh(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

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

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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.

Examples

>>> import arkouda as ak
>>> a = ak.linspace(-.999,.999,4)
>>> ak.arctanh(a)
array([-3.80020116... -0.34619863... 0.34619863... 3.80020116...])
arkouda.numpy.numeric.array_equal(pda_a: arkouda.numpy.pdarrayclass.pdarray, pda_b: arkouda.numpy.pdarrayclass.pdarray, equal_nan: bool = False) bool[source]

Compares two pdarrays for equality. If neither array has any nan elements, then if all elements are pairwise equal, it returns True. If equal_Nan is False, then any nan element in either array gives a False return. If equal_Nan is True, then pairwise-corresponding nans are considered equal.

Parameters:
  • pda_a (pdarray)

  • pda_b (pdarray)

  • equal_nan (bool, default=False) – Determines how to handle nans

Returns:

With string data:

False if one array is type ak.str_ & the other isn’t, True if both are ak.str_ & they match.

With numeric data:

True if neither array has any nan elements, and all elements pairwise equal.

True if equal_Nan True, all non-nans pairwise equal & nans in pda_a correspond to nans in pda_b

False if equal_Nan False, & either array has any nan element.

Return type:

boolean

Examples

>>> import arkouda as ak
>>> a = ak.randint(0,10,10,dtype=ak.float64)
>>> b = a
>>> ak.array_equal(a,b)
True
>>> b[9] = np.nan
>>> ak.array_equal(a,b)
False
>>> a[9] = np.nan
>>> ak.array_equal(a,b)
False
>>> ak.array_equal(a,b,True)
True
arkouda.numpy.numeric.cast(pda: arkouda.numpy.pdarrayclass.pdarray, dt: arkouda.numpy._typing.StringDTypeTypes, errors: Literal[ErrorMode, ErrorMode] = ErrorMode.strict) arkouda.numpy.strings.Strings[source]
arkouda.numpy.numeric.cast(pda: arkouda.numpy.pdarrayclass.pdarray, dt: arkouda.numpy._typing.NumericDTypeTypes, errors: Literal[ErrorMode, ErrorMode] = ErrorMode.strict) arkouda.numpy.pdarrayclass.pdarray
arkouda.numpy.numeric.cast(pda: arkouda.numpy.strings.Strings, dt: arkouda.numpy._typing.ArkoudaNumericTypes | arkouda.numpy._typing.BuiltinNumericTypes | numpy.dtype[Any] | arkouda.numpy.dtypes.bigint, errors: Literal[ErrorMode]) Tuple[arkouda.numpy.pdarrayclass.pdarray, arkouda.numpy.pdarrayclass.pdarray]
arkouda.numpy.numeric.cast(pda: arkouda.numpy.strings.Strings, dt: arkouda.numpy._typing.ArkoudaNumericTypes | arkouda.numpy._typing.BuiltinNumericTypes | numpy.dtype[Any] | arkouda.numpy.dtypes.bigint, errors: Literal[ErrorMode, ErrorMode] = ErrorMode.strict) arkouda.numpy.pdarrayclass.pdarray
arkouda.numpy.numeric.cast(pda: arkouda.numpy.strings.Strings, dt: arkouda.numpy._typing.StringDTypeTypes, errors: Literal[ErrorMode, ErrorMode] = ErrorMode.strict) arkouda.numpy.strings.Strings
arkouda.numpy.numeric.cast(pda: arkouda.numpy.strings.Strings, dt: type[arkouda.pandas.categorical.Categorical], errors: Literal[ErrorMode, ErrorMode] = ErrorMode.strict) arkouda.pandas.categorical.Categorical
arkouda.numpy.numeric.cast(pda: arkouda.pandas.categorical.Categorical, dt: arkouda.numpy._typing.StringDTypeTypes, errors: Literal[ErrorMode, ErrorMode] = ErrorMode.strict) arkouda.numpy.strings.Strings
arkouda.numpy.numeric.cast(pda: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.dtypes.numeric_scalars, dt: arkouda.numpy._typing.ArkoudaNumericTypes | arkouda.numpy._typing.BuiltinNumericTypes | numpy.dtype[Any] | arkouda.numpy.dtypes.bigint | None, errors: Literal[ErrorMode, ErrorMode] = ErrorMode.strict) arkouda.numpy.pdarrayclass.pdarray
arkouda.numpy.numeric.cast(pda: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings | arkouda.pandas.categorical.Categorical | arkouda.numpy.dtypes.numeric_scalars, dt: str, errors: Literal[ErrorMode, ErrorMode] = ErrorMode.strict) arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings | arkouda.pandas.categorical.Categorical

Cast an array to another dtype.

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

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

  • errors ({strict, ignore, return_validity}, default=ErrorMode.strict) –

    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.

    Default set to strict.

Returns:

pdarray or Strings

Array of values cast to desired dtype

[validitypdarray(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.

Return type:

Union[Union[pdarray, Strings, Categorical], Tuple[pdarray, pdarray]]

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

>>> import arkouda as ak
>>> 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.numpy.numeric.ceil(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

Return the element-wise ceiling of the array.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – This condition is applied over the input. At locations where the condition is True, the corresponding value will be acted on by the function. Elsewhere, it will retain its original value. Default set to True.

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

>>> import arkouda as ak
>>> ak.ceil(ak.linspace(1.1,5.5,5))
array([2.00000000... 3.00000000... 4.00000000... 5.00000000... 6.00000000...])
arkouda.numpy.numeric.clip(pda: arkouda.numpy.pdarrayclass.pdarray, lo: arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray, hi: arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.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) – the array of values to clip

  • lo (numeric_scalars or pdarray) – the lower value of the clipping range

  • hi (numeric_scalars or pdarray) – the higher value of the clipping range If lo or hi (or both) are pdarrays, the check is by pairwise elements. 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:

pdarray

Examples

>>> import arkouda as ak
>>> 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.00000000... 3.00000000... 3.00000000... 4.00000000...
       5.00000000... 6.00000000... 7.00000000... 8.00000000...
       8.00000000... 8.00000000...])
>>> 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.numpy.numeric.cos(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

Return the element-wise cosine of the array.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(-1.5,0.75,4)
>>> ak.cos(a)
array([0.07073720... 0.73168886... 1.00000000... 0.73168886...])
arkouda.numpy.numeric.cosh(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

Return the element-wise hyperbolic cosine of the array.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(-0.9,0.7,4)
>>> ak.cosh(a)
array([1.43308638... 1.06797874... 1.01392106... 1.25516900...])
arkouda.numpy.numeric.count_nonzero(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.dtypes.int_scalars[source]

Compute the nonzero count of a given array. 1D case only, for now.

Parameters:

pda (pdarray) – The input data, in pdarray form, numeric, bool, or str

Returns:

The nonzero count of the entire pdarray

Return type:

int_scalars

Raises:
  • TypeError – Raised if the parameter is not a pdarray with numeric, bool, or str datatype

  • ValueError – Raised if sum applied to the pdarray doesn’t come back with a scalar

Examples

>>> import arkouda as ak
>>> pda = ak.array([0,4,7,8,1,3,5,2,-1])
>>> ak.count_nonzero(pda)
np.int64(8)
>>> pda = ak.array([False,True,False,True,False])
>>> ak.count_nonzero(pda)
np.int64(2)
>>> pda = ak.array(["hello","","there"])
>>> ak.count_nonzero(pda)
np.int64(2)
arkouda.numpy.numeric.cumprod(pda: arkouda.numpy.pdarrayclass.pdarray, axis: int | None | None = None) arkouda.numpy.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)

  • axis (int, optional) – the axis along which to compute the product

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

  • ValueError – Raised if an invalid axis is given

Examples

>>> import arkouda as ak
>>> ak.cumprod(ak.arange(1,5))
array([1 2 6 24])
>>> ak.cumprod(ak.uniform(5,1.0,5.0, seed=1))
array([4.14859379... 5.54704379... 22.20109135... 79.7021268... 298.2655159...])
>>> ak.cumprod(ak.randint(0, 2, 5, dtype=ak.bool_, seed=1))
array([1 0 0 0 0])
arkouda.numpy.numeric.cumsum(pda: arkouda.numpy.pdarrayclass.pdarray, axis: int | None | None = None) arkouda.numpy.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)

  • axis (int, optional) – the axis along which to compute the sum

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

  • ValueError – Raised if an invalid axis is given

Examples

>>> import arkouda as ak
>>> ak.cumsum(ak.arange(1,5))
array([1 3 6 10])
>>> ak.cumsum(ak.uniform(5,1.0,5.0, seed=1))
array([4.14859379... 5.48568392... 9.48801240... 13.0780218... 16.8202747...])
>>> ak.cumsum(ak.randint(0, 2, 5, dtype=ak.bool_, seed=1))
array([1 1 2 3 4])
arkouda.numpy.numeric.deg2rad(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

Converts angles element-wise from degrees to radians.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(0,359,4)
>>> ak.deg2rad(a)
array([0.00000000... 2.08857733... 4.17715467... 6.26573201...])
arkouda.numpy.numeric.exp(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.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

>>> import arkouda as ak
>>> ak.exp(ak.arange(1,5))
array([2.71828182... 7.38905609... 20.0855369... 54.5981500...])
>>> ak.exp(ak.uniform(4, 1.0, 5.0, seed=1))
array([63.3448620... 3.80794671... 54.7254287... 36.2344168...])
arkouda.numpy.numeric.expm1(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.pdarrayclass.pdarray[source]

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

Parameters:

pda (pdarray)

Returns:

A pdarray containing e raised to each of the inputs, then subtracting one.

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> import arkouda as ak
>>> ak.expm1(ak.arange(1,5))
array([1.71828182... 6.38905609... 19.0855369... 53.5981500...])
>>> ak.expm1(ak.uniform(5,1.0,5.0, seed=1))
array([62.3448620... 2.80794671... 53.7254287...
    35.2344168... 41.1929399...])
arkouda.numpy.numeric.eye(N: arkouda.numpy.dtypes.int_scalars, M: arkouda.numpy.dtypes.int_scalars, k: arkouda.numpy.dtypes.int_scalars = 0, dt: type = ak_float64) arkouda.numpy.pdarrayclass.pdarray[source]

Return a pdarray with zeros everywhere except along a diagonal, which is all ones. The matrix need not be square.

Parameters:
  • N (int_scalars)

  • M (int_scalars)

  • k (int_scalars, default=0) –

    if k = 0, zeros start at element [0,0] and proceed along diagonal
    if k > 0, zeros start at element [0,k] and proceed along diagonal
    if k < 0, zeros start at element [k,0] and proceed along diagonal

  • dt (type, default=ak_float64) – The data type of the elements in the matrix being returned. Default set to ak_float64

Returns:

an array of zeros with ones along the specified diagonal

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> ak.eye(N=4,M=4,k=0,dt=ak.int64)
array([array([1 0 0 0]) array([0 1 0 0]) array([0 0 1 0]) array([0 0 0 1])])
>>> ak.eye(N=3,M=3,k=1,dt=ak.float64)
array([array([0.00000000... 1.00000000... 0.00000000...])
array([0.00000000... 0.00000000... 1.00000000...])
array([0.00000000... 0.00000000... 0.00000000...])])
>>> ak.eye(N=4,M=4,k=-1,dt=ak.bool_)
array([array([False False False False]) array([True False False False])
array([False True False False]) array([False False True False])])

Notes

if N = M and k = 0, the result is an identity matrix Server returns an error if rank of pda < 2

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

Compute the absolute values element-wise, casting to a float beforehand.

Parameters:

pda (pdarray)

Returns:

A pdarray containing absolute values of the input array elements, casted to float type

Return type:

pdarray

Raises:

TypeError – Raised if the parameter is not a pdarray

Examples

>>> import arkouda as ak
>>> ak.fabs(ak.arange(-5,-1))
array([5.00000000000000000 4.00000000000000000 3.00000000000000000 2.00000000000000000])
>>> ak.fabs(ak.linspace(-5,-1,5))
array([5.00000000... 4.00000000... 3.00000000...
2.00000000... 1.00000000...])
arkouda.numpy.numeric.floor(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

Return the element-wise floor of the array.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – This condition is applied over the input. At locations where the condition is True, the corresponding value will be acted on by the function. Elsewhere, it will retain its original value. Default set to True.

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

>>> import arkouda as ak
>>> ak.floor(ak.linspace(1.1,5.5,5))
array([1.00000000... 2.00000000... 3.00000000...
4.00000000... 5.00000000...])
arkouda.numpy.numeric.hash(pda: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings | arkouda.numpy.segarray.SegArray | arkouda.pandas.categorical.Categorical | List[arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings | arkouda.numpy.segarray.SegArray | arkouda.pandas.categorical.Categorical], full: bool = True) Tuple[arkouda.numpy.pdarrayclass.pdarray, arkouda.numpy.pdarrayclass.pdarray] | arkouda.numpy.pdarrayclass.pdarray[source]

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

Parameters:
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

Examples

>>> import arkouda as ak
>>> a = ak.randint(0,65536,3,seed=8675309)
>>> ak.hash(a,full=False)
array([6132219720275344925 189443193828113335 14797568559700425150])
>>> ak.hash(a)
(array([12228890592923494910 17773622519799422780 16661993598191972647]),
    array([2936052102410048944 15730675498625067356 4746877828134486787]))

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.numpy.numeric.histogram(pda: arkouda.numpy.pdarrayclass.pdarray, bins: arkouda.numpy.dtypes.int_scalars = 10, range: Tuple[arkouda.numpy.dtypes.numeric_scalars, arkouda.numpy.dtypes.numeric_scalars] | None = None) Tuple[arkouda.numpy.pdarrayclass.pdarray, arkouda.numpy.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, default=10) – The number of equal-size bins to use (default: 10)

  • range ((minVal, maxVal), optional) – The range of the values to count. Values outside of this range are dropped. By default, all values are counted.

Returns:

The number of values present in each bin and the bin edges

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()]. If range parameter is provided, the interval is [range[0], range[1]].

Examples

>>> import arkouda as ak
>>> 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.00000000... 3.00000000... 6.00000000... 9.00000000...])

To plot, export the left edges and the histogram to NumPy >>> b_np = b.to_ndarray() >>> import numpy as np >>> b_widths = np.diff(b_np) >>> plt.bar(b_np[:-1], h.to_ndarray(), width=b_widths, align=’edge’, edgecolor=’black’) <BarContainer object of 3 artists> >>> plt.show() # doctest: +SKIP

arkouda.numpy.numeric.histogram2d(x: arkouda.numpy.pdarrayclass.pdarray, y: arkouda.numpy.pdarrayclass.pdarray, bins: arkouda.numpy.dtypes.int_scalars | Sequence[arkouda.numpy.dtypes.int_scalars] = 10, range: Tuple[Tuple[arkouda.numpy.dtypes.numeric_scalars, arkouda.numpy.dtypes.numeric_scalars], Tuple[arkouda.numpy.dtypes.numeric_scalars, arkouda.numpy.dtypes.numeric_scalars]] | None = None) Tuple[arkouda.numpy.pdarrayclass.pdarray, arkouda.numpy.pdarrayclass.pdarray, arkouda.numpy.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], default=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

  • range (((xMin, xMax), (yMin, yMax)), optional) – The ranges of the values in x and y to count. Values outside of these ranges are dropped. By default, all values are counted.

Returns:

histpdarray

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_edgespdarray

The bin edges along the first dimension.

y_edgespdarray

The bin edges along the second dimension.

Return type:

Tuple[pdarray, pdarray, pdarray]

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()]. If range parameter is provided, the intervals are given by range[0] for x and range[1] for y..

Examples

>>> import arkouda as ak
>>> 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([array([0.00000000... 0.00000000... 3.00000000...])
       array([0.00000000... 2.00000000... 1.00000000...])
       array([3.00000000... 1.00000000... 0.00000000...])])
>>> x_edges
array([0.00000000... 3.00000000... 6.00000000... 9.00000000...])
>>> y_edges
array([0.00000000... 3.00000000... 6.00000000... 9.00000000...])
arkouda.numpy.numeric.histogramdd(sample: Sequence[arkouda.numpy.pdarrayclass.pdarray], bins: arkouda.numpy.dtypes.int_scalars | Sequence[arkouda.numpy.dtypes.int_scalars] = 10, range: Sequence[Tuple[arkouda.numpy.dtypes.numeric_scalars, arkouda.numpy.dtypes.numeric_scalars] | None] | None = None) Tuple[arkouda.numpy.pdarrayclass.pdarray, Sequence[arkouda.numpy.pdarrayclass.pdarray]][source]

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

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

  • bins (int_scalars or Sequence of int_scalars, default=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

  • range (Sequence[optional (minVal, maxVal)], optional) – The ranges of the values to count for each array in sample. Values outside of these ranges are dropped. By default, all values are counted.

Returns:

histpdarray

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.

edgesList[pdarray]

A list of pdarrays containing the bin edges for each dimension.

Return type:

Tuple[pdarray, Sequence[pdarray]]

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()] or in the inverval determined by range[dimension], if provided.

Examples

>>> import arkouda as ak
>>> 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,3))
>>> h
array([array([array([0.00000000... 0.00000000... 0.00000000...])
    array([2.00000000... 1.00000000... 2.00000000...])])
    array([array([2.00000000... 1.00000000... 2.00000000...])
    array([0.00000000... 0.00000000... 0.00000000...])])])
>>> edges
[array([0.00000000... 4.5 9.00000000...]),
    array([0.00000000... 4.5 9.00000000...]),
    array([0.00000000... 2.66666666... 5.33333333... 8.00000000...])]
arkouda.numpy.numeric.isfinite(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.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

>>> import arkouda as ak
>>> ak.isfinite(ak.array([1.0, 2.0, ak.inf]))
array([True True False])
arkouda.numpy.numeric.isinf(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.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 (positive or negative)

Return type:

pdarray

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

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

Examples

>>> import arkouda as ak
>>> ak.isinf(ak.array([1.0, 2.0, ak.inf]))
array([False False True])
arkouda.numpy.numeric.isnan(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.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

>>> import arkouda as ak
>>> ak.isnan(ak.array([1.0, 2.0, np.log(-1)]))
array([False False True])
arkouda.numpy.numeric.log(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.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

>>> import arkouda as ak
>>> A = ak.array([1, 10, 100])

Natural log >>> ak.log(A) array([0.00000000… 2.30258509… 4.60517018…])

Log base 10 >>> ak.log(A) / np.log(10) array([0.00000000… 1.00000000… 2.00000000…])

Log base 2 >>> ak.log(A) / np.log(2) array([0.00000000… 3.32192809… 6.64385618…])

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

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

Parameters:

pda (pdarray) – array to compute on

Returns:

pdarray containing base 10 log values of the input array elements

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> a = ak.arange(1,5)
>>> ak.log10(a)
array([0.00000000... 0.30102999... 0.47712125... 0.60205999...])
arkouda.numpy.numeric.log1p(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.pdarrayclass.pdarray[source]

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

Parameters:

pda (pdarray) – array to compute on

Returns:

pdarray containing natural log values of the input array elements, adding one before taking the log

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> ak.log1p(ak.arange(1,5))
array([0.69314718... 1.09861228... 1.38629436... 1.60943791...])
arkouda.numpy.numeric.log2(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.pdarrayclass.pdarray[source]

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

Parameters:

pda (pdarray) – array to compute on

Returns:

pdarray containing base 2 log values of the input array elements

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> a = ak.arange(1,5)
>>> ak.log2(a)
array([0.00000000... 1.00000000... 1.58496250... 2.00000000...])
arkouda.numpy.numeric.matmul(pda_L: arkouda.numpy.pdarrayclass.pdarray, pda_R: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.pdarrayclass.pdarray[source]

Compute the product of two matrices. If both are 1D, this returns a simple dot product. If both are 2D, it returns a conventional matrix multiplication. If only one is 1D, the result matches the “dot” function, so we use that. If neither is 1D and at least one is > 2D, then broadcasting is involved. If pda_L’s shape is [(leftshape),m,n] and pda_R’s shape is [(rightshape),n,k], then the result will have shape [(common shape),m,k] where common shape is a shape that both leftshape and rightshape can be broadcast to.

Parameters:
Returns:

the matrix product pda_L x pda_R

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> a = ak.array([[1,2,3,4,5],[1,2,3,4,5]])
>>> b = ak.array([[1,1],[2,2],[3,3],[4,4],[5,5]])
>>> ak.matmul(a,b)
array([array([55 55]) array([55 55])])
>>> x = ak.array([[1,2,3],[1.1,2.1,3.1]])
>>> y = ak.array([[1,1,1],[0,2,2],[0,0,3]])
>>> ak.matmul(x,y)
array([array([1.00000000... 5.00000000... 14.0000000...])
array([1.10000000... 5.30000000... 14.6000000...])])
Raises:

ValueError – Raised if shapes are incompatible with matrix multiplication.

arkouda.numpy.numeric.median(pda: arkouda.numpy.pdarrayclass.pdarray) numpy.float64[source]

Compute the median of a given array. 1d case only, for now.

Parameters:

pda (pdarray) – The input data, in pdarray form, numeric type or boolean

Returns:

The median of the entire pdarray
The array is sorted, and then if the number of elements is odd, the return value is the middle element. If even, then the mean of the two middle elements.

Return type:

np.float64

Examples

>>> import arkouda as ak
>>> pda = ak.array([0,4,7,8,1,3,5,2,-1])
>>> ak.median(pda)
np.float64(3.0)
>>> pda = ak.array([0,1,3,3,1,2,3,4,2,3])
>>> ak.median(pda)
np.float64(2.5)
arkouda.numpy.numeric.nextafter(x1: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.dtypes.bigint, x2: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.dtypes.bigint) arkouda.numpy.pdarrayclass.pdarray | float[source]

Return the next floating-point value after x1 towards x2, element-wise. Accuracy only guaranteed for 64 bit values.

Parameters:
  • x1 (pdarray, numeric_scalars, or bigint) – Values to find the next representable value of.

  • x2 (pdarray, numeric_scalars, or bigint) – The direction where to look for the next representable value of x1. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).

Returns:

The next representable values of x1 in the direction of x2. This is a scalar if both x1 and x2 are scalars.

Return type:

pdarray or float

Examples

>>> import arkouda as ak
>>> eps = np.finfo(np.float64).eps
>>> ak.nextafter(1, 2) == 1 + eps
 np.True_
>>> a = ak.array([1, 2])
>>> b = ak.array([2, 1])
>>> ak.nextafter(a, b) == ak.array([eps + 1, 2 - eps])
array([True True])
arkouda.numpy.numeric.percentile(a: arkouda.numpy.pdarrayclass.pdarray, q: arkouda.numpy.dtypes.numeric_scalars | Tuple[arkouda.numpy.dtypes.numeric_scalars] | numpy.ndarray | None = 0.5, axis: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | None | None = None, method: str | None = 'linear', keepdims: bool = False) arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray[source]

Compute the q-th percentile of the data along the specified axis.

Parameters:
  • a (pdarray) – data whose percentile will be computed

  • q (pdarray, Tuple, or np.ndarray) – a scalar, tuple, or np.ndarray of q values for the computation. All values must be in the range 0 <= q <= 100

  • axis (None, int scalar, or tuple of int scalars) – the axis or axes along which the percentiles are computed. The default is None, which computes the percenntile along a flattened version of the array.

  • method (string) – one of “inverted_cdf,” “averaged_inverted_cdf”, “closest_observation”, “interpolated_inverted_cdf”, “hazen”, “weibull”, “linear”, ‘median_unbiased”, “normal_unbiased”, “lower”,” higher”, “midpoint”

  • keepdims (bool) – True if the degenerate axes are to be retained after slicing, False if not

Returns:

If q is a scalar and axis is None, the result is a scalar. If q is a scalar and axis is supplied, the result is a pdarray of rank len(axis) less than the rank of a. If q is an array and axis is None, the result is a pdarray of shape q.shape If q is an array and axis is None, the result is a pdarray of rank q.ndim + pda.ndim - len(axis). However, there is an intermediate result which is of rank q.ndim + pda.ndim. If this is not in the compiled ranks, an error will be thrown even if the final result would be in the compiled ranks.

Return type:

pdarray or scalar

Notes

np.percentile also supports the method “nearest,” however its behavior does not match the numpy documentation, so it’s not supported here. np.percentile also allows for weighted inputs, but only for the method “inverted_cdf.” That also is not supported here.

Examples

>>> import arkouda as ak
>>> a = ak.array([[1,2,3,4,5],[1,2,3,4,5]])
>>> q = 70
>>> ak.percentile(a,q,axis=None,method="linear")
np.float64(4.0)
>>> ak.percentile(a,q,axis=1,method="lower")
array([3.00000000... 3.00000000...])
>>> q = np.array([40,60])
>>> ak.percentile(a,q,axis=None,method="weibull")
array([2.40000000... 3.59999999...])
>>> a = ak.array([[1,2],[5,3]])
>>> ak.percentile(a,q,axis=0,method="hazen")
array([array([2.20000000... 2.29999999...])
    array([3.79999999... 2.69999999...])])
Raises:

ValueError – Raised if scalar q or any value of array q is outside the range [0,100] Raised if the method is not one of the 12 supported methods. Raised if the result would have a rank not in the compiled ranks.

arkouda.numpy.numeric.putmask(A: arkouda.numpy.pdarrayclass.pdarray, mask: arkouda.numpy.pdarrayclass.pdarray, Values: arkouda.numpy.pdarrayclass.pdarray) None[source]

Overwrite elements of A with elements from B based upon a mask array. Similar to numpy.putmask, where mask = False, A retains its original value, but where mask = True, A is overwritten with the corresponding entry from Values.

This is similar to ak.where, except that (1) no new pdarray is created, and (2) Values does not have to be the same size as A and mask.

Parameters:
  • A (pdarray) – Value(s) used when mask is False (see Notes for allowed dtypes)

  • mask (pdarray) – Used to choose values from A or B, must be same size as A, and of type ak.bool_

  • Values (pdarray) – Value(s) used when mask is False (see Notes for allowed dtypes)

Examples

>>> import arkouda as ak
>>> a = ak.array(np.arange(10))
>>> ak.putmask (a,a>2,a**2)
>>> a
array([0 1 2 9 16 25 36 49 64 81])
>>> a = ak.array(np.arange(10))
>>> values = ak.array([3,2])
>>> ak.putmask (a,a>2,values)
>>> a
array([0 1 2 2 3 2 3 2 3 2])
Raises:

RuntimeError – Raised if mask is not same size as A, or if A.dtype and Values.dtype are not an allowed pair (see Notes for details).

Notes

A and mask must be the same size. Values can be any size.
Allowed dtypes for A and Values conform to types accepted by numpy putmask.
If A is ak.float64, Values can be ak.float64, ak.int64, ak.uint64, ak.bool_.
If A is ak.int64, Values can be ak.int64 or ak.bool_.
If A is ak.uint64, Values can be ak.uint64, or ak.bool_.
If A is ak.bool_, Values must be ak.bool_.

Only one conditional clause is supported e.g., n < 5, n > 1.

multi-dim pdarrays are now implemented.

arkouda.numpy.numeric.quantile(a: arkouda.numpy.pdarrayclass.pdarray, q: arkouda.numpy.dtypes.numeric_scalars | Tuple[arkouda.numpy.dtypes.numeric_scalars] | numpy.ndarray | arkouda.numpy.pdarrayclass.pdarray | None = 0.5, axis: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | None | None = None, method: str | None = 'linear', keepdims: bool = False) arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray[source]

Compute the q-th quantile of the data along the specified axis.

Parameters:
  • a (pdarray) – data whose quantile will be computed

  • q (pdarray, Tuple, or np.ndarray) – a scalar, tuple, or np.ndarray of q values for the computation. All values must be in the range 0 <= q <= 1

  • axis (None, int scalar, or tuple of int scalars) – the axis or axes along which the quantiles are computed. The default is None, which computes the quantile along a flattened version of the array.

  • method (string) – one of “inverted_cdf,” “averaged_inverted_cdf”, “closest_observation”, “interpolated_inverted_cdf”, “hazen”, “weibull”, “linear”, ‘median_unbiased”, “normal_unbiased”, “lower”,” higher”, “midpoint”

  • keepdims (bool) – True if the degenerate axes are to be retained after slicing, False if not

Returns:

If q is a scalar and axis is None, the result is a scalar. If q is a scalar and axis is supplied, the result is a pdarray of rank len(axis) less than the rank of a. If q is an array and axis is None, the result is a pdarray of shape q.shape If q is an array and axis is None, the result is a pdarray of rank q.ndim + pda.ndim - len(axis). However, there is an intermediate result which is of rank q.ndim + pda.ndim. If this is not in the compiled ranks, an error will be thrown even if the final result would be in the compiled ranks.

Return type:

pdarray or scalar

Notes

np.quantile also supports the method “nearest,” however its behavior does not match the numpy documentation, so it’s not supported here. np.quantile also allows for weighted inputs, but only for the method “inverted_cdf.” That also is not supported here.

Examples

>>> import arkouda as ak
>>> a = ak.array([[1,2,3,4,5],[1,2,3,4,5]])
>>> q = 0.7
>>> ak.quantile(a,q,axis=None,method="linear")
np.float64(4.0)
>>> ak.quantile(a,q,axis=1,method="lower")
array([3.00000000... 3.00000000...])
>>> q = np.array([0.4,0.6])
>>> ak.quantile(a,q,axis=None,method="weibull")
array([2.40000000... 3.59999999...])
>>> a = ak.array([[1,2],[5,3]])
>>> ak.quantile(a,q,axis=0,method="hazen")
array([array([2.20000000... 2.29999999...])
    array([3.79999999... 2.69999999...])])
Raises:

ValueError – Raised if scalar q or any value of array q is outside the range [0,1] Raised if the method is not one of the 12 supported methods. Raised if the result would have a rank not in the compiled ranks.

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

Converts angles element-wise from radians to degrees.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(0,6.28,4)
>>> ak.rad2deg(a)
array([0.00000000... 119.939165... 239.878330... 359.817495...])
arkouda.numpy.numeric.round(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

Return the element-wise rounding of the array.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – This condition is applied over the input. At locations where the condition is True, the corresponding value will be acted on by the function. Elsewhere, it will retain its original value. Default set to True.

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

>>> import arkouda as ak
>>> ak.round(ak.array([1.1, 2.5, 3.14159]))
array([1.00000000... 3.00000000... 3.00000000...])
arkouda.numpy.numeric.sign(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.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

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

Return the element-wise sine of the array.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(-1.5,0.75,4)
>>> ak.sin(a)
array([-0.99749498... -0.68163876... 0.00000000... 0.68163876...])
arkouda.numpy.numeric.sinh(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

Return the element-wise hyperbolic sine of the array.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(-0.9,0.7,4)
>>> ak.sinh(a)
array([-1.02651672... -0.37493812... 0.16743934... 0.75858370...])
arkouda.numpy.numeric.square(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

Return the element-wise square of the array.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – This condition is applied over the input. At locations where the condition is True, the corresponding value will be acted on by the function. Elsewhere, it will retain its original value. Default set to True.

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

>>> import arkouda as ak
>>> ak.square(ak.arange(1,5))
array([1 4 9 16])
arkouda.numpy.numeric.take(a: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings, indices: arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray | Iterable[arkouda.numpy.dtypes.numeric_scalars], axis: int | None = None) arkouda.numpy.pdarrayclass.pdarray[source]

Take elements from an array along an axis.

When axis is not None, this function does the same thing as “fancy” indexing (indexing arrays using arrays); however, it can be easier to use if you need elements along a given axis. A call such as np.take(arr, indices, axis=3) is equivalent to arr[:,:,:,indices,...].

Parameters:
  • a (pdarray or Strings) – The array from which to take elements

  • indices (numeric_scalars or pdarray or Iterable[numeric_scalars]) – The indices of the values to extract. Also allow scalars for indices.

  • axis (int, optional) – The axis over which to select values. By default, the flattened input array is used.

Returns:

The returned array has the same type as a.

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> a = ak.array([4, 3, 5, 7, 6, 8])
>>> indices = [0, 1, 4]
>>> ak.take(a, indices)
array([4 3 6])
arkouda.numpy.numeric.tan(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

Return the element-wise tangent of the array.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(-1.5,0.75,4)
>>> ak.tan(a)
array([-14.1014199... -0.93159645... 0.00000000... 0.93159645...])
arkouda.numpy.numeric.tanh(pda: arkouda.numpy.pdarrayclass.pdarray, where: bool | arkouda.numpy.pdarrayclass.pdarray = True) arkouda.numpy.pdarrayclass.pdarray[source]

Return the element-wise hyperbolic tangent of the array.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – 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

Examples

>>> import arkouda as ak
>>> a = ak.linspace(-0.9,0.7,4)
>>> ak.tanh(a)
array([-0.71629787... -0.35107264... 0.16514041... 0.60436777...])
arkouda.numpy.numeric.transpose(pda: arkouda.numpy.pdarrayclass.pdarray, axes: Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | None = None) arkouda.numpy.pdarrayclass.pdarray[source]

Compute the transpose of a matrix.

Parameters:
  • pda (pdarray)

  • axes (Tuple[int,...] Optional, defaults to None) – If specified, must be a tuple which contains a permutation of the axes of pda.

Returns:

the transpose of the input matrix For a 1-D array, this is the original array. For a 2-D array, this is the standard matrix transpose. For an n-D array, if axes are given, their order indicates how the axes are permuted. If axes is None, the axes are reversed.

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> a = ak.array([[1,2,3,4,5],[1,2,3,4,5]])
>>> ak.transpose(a)
array([array([1 1]) array([2 2]) array([3 3]) array([4 4]) array([5 5])])
>>> z = ak.array(np.arange(27).reshape(3,3,3))
>>> ak.transpose(z,axes=(1,0,2))
array([array([array([0 1 2]) array([9 10 11]) array([18 19 20])]) array([array([3 4 5])
  array([12 13 14]) array([21 22 23])]) array([array([6 7 8]) array([15 16 17]) array([24 25 26])])])
Raises:
  • ValueError – Raised if axes is not a legitimate permutation of the axes of pda

  • TypeError – Raised if pda is not a pdarray, or if axes is neither a tuple nor None

arkouda.numpy.numeric.tril(pda: arkouda.numpy.pdarrayclass.pdarray, diag: arkouda.numpy.dtypes.int_scalars = 0) arkouda.numpy.pdarrayclass.pdarray[source]

Return a copy of the pda with the upper triangle zeroed out.

Parameters:
  • pda (pdarray)

  • diag (int_scalars, optional) –

    if diag = 0, zeros start just above the main diagonal
    if diag = 1, zeros start at the main diagonal
    if diag = 2, zeros start just below the main diagonal
    etc. Default set to 0.

Returns:

a copy of pda with zeros in the upper triangle

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> a = ak.array([[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8],[5,6,7,8,9]])
>>> ak.tril(a,diag=4)
array([array([1 2 3 4 5]) array([2 3 4 5 6]) array([3 4 5 6 7])
array([4 5 6 7 8]) array([5 6 7 8 9])])
>>> ak.tril(a,diag=3)
array([array([1 2 3 4 0]) array([2 3 4 5 6]) array([3 4 5 6 7])
array([4 5 6 7 8]) array([5 6 7 8 9])])
>>> ak.tril(a,diag=2)
array([array([1 2 3 0 0]) array([2 3 4 5 0]) array([3 4 5 6 7])
array([4 5 6 7 8]) array([5 6 7 8 9])])
>>> ak.tril(a,diag=1)
array([array([1 2 0 0 0]) array([2 3 4 0 0]) array([3 4 5 6 0])
array([4 5 6 7 8]) array([5 6 7 8 9])])
>>> ak.tril(a,diag=0)
array([array([1 0 0 0 0]) array([2 3 0 0 0]) array([3 4 5 0 0])
array([4 5 6 7 0]) array([5 6 7 8 9])])

Notes

Server returns an error if rank of pda < 2

arkouda.numpy.numeric.triu(pda: arkouda.numpy.pdarrayclass.pdarray, diag: arkouda.numpy.dtypes.int_scalars = 0) arkouda.numpy.pdarrayclass.pdarray[source]

Return a copy of the pda with the lower triangle zeroed out.

Parameters:
  • pda (pdarray)

  • diag (int_scalars, default=0) –

    if diag = 0, zeros start just below the main diagonal
    if diag = 1, zeros start at the main diagonal
    if diag = 2, zeros start just above the main diagonal
    etc. Default set to 0.

Returns:

a copy of pda with zeros in the lower triangle

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> a = ak.array([[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8],[5,6,7,8,9]])
>>> ak.triu(a,diag=0)
array([array([1 2 3 4 5]) array([0 3 4 5 6]) array([0 0 5 6 7])
array([0 0 0 7 8]) array([0 0 0 0 9])])
>>> ak.triu(a,diag=1)
array([array([0 2 3 4 5]) array([0 0 4 5 6]) array([0 0 0 6 7])
array([0 0 0 0 8]) array([0 0 0 0 0])])
>>> ak.triu(a,diag=2)
array([array([0 0 3 4 5]) array([0 0 0 5 6]) array([0 0 0 0 7])
array([0 0 0 0 0]) array([0 0 0 0 0])])
>>> ak.triu(a,diag=3)
array([array([0 0 0 4 5]) array([0 0 0 0 6]) array([0 0 0 0 0])
array([0 0 0 0 0]) array([0 0 0 0 0])])
>>> ak.triu(a,diag=4)
array([array([0 0 0 0 5]) array([0 0 0 0 0]) array([0 0 0 0 0])
array([0 0 0 0 0]) array([0 0 0 0 0])])

Notes

Server returns an error if rank of pda < 2

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

Return the element-wise truncation of the array.

Parameters:
  • pda (pdarray)

  • where (bool or pdarray, default=True) – This condition is applied over the input. At locations where the condition is True, the corresponding value will be acted on by the function. Elsewhere, it will retain its original value. Default set to True.

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

>>> import arkouda as ak
>>> ak.trunc(ak.array([1.1, 2.5, 3.14159]))
array([1.00000000... 2.00000000... 3.00000000...])
arkouda.numpy.numeric.value_counts(pda: arkouda.numpy.pdarrayclass.pdarray) tuple[arkouda.groupbyclass.groupable, arkouda.numpy.pdarrayclass.pdarray][source]

Count the occurrences of the unique values of an array.

Parameters:

pda (pdarray) – 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

>>> import arkouda as ak
>>> A = ak.array([2, 0, 2, 4, 0, 0])
>>> ak.value_counts(A)
(array([0 2 4]), array([3 2 1]))
arkouda.numpy.numeric.vecdot(x1: arkouda.numpy.pdarrayclass.pdarray, x2: arkouda.numpy.pdarrayclass.pdarray, axis: int | None | None = None) arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray[source]

Computes the numpy-style vecdot product of two matrices. This differs from the vecdot function above. See https://numpy.org/doc/stable/reference/index.html.

Parameters:
  • x1 (pdarray)

  • x2 (pdarray)

  • axis (int, None, optional, default = None)

Returns:

x1 vecdot x2

Return type:

pdarray, numeric_scalar

Examples

>>> import arkouda as ak
>>> a = ak.array([[1,2,3,4,5],[1,2,3,4,5]])
>>> b = ak.array([[2,2,2,2,2],[2,2,2,2,2]])
>>> ak.vecdot(a,b)
array([30 30])
>>> ak.vecdot(b,a)
array([30 30])
Raises:

ValueError – Raised if x1 and x2 can not be broadcast to a compatible shape or if the last dimensions of x1 and x2 don’t match.

Notes

This matches the behavior of numpy vecdot, but as commented above, it is not the behavior of the deprecated vecdot, which calls the chapel-side vecdot function. This function only uses broadcast_to, broadcast_shapes, ak.sum, and the binops pdarray multiplication function. The last dimension of x1 and x2 must match, and it must be possible to broadcast them to a compatible shape. The deprecated vecdot can be computed via ak.vecdot(a,b,axis=0) on pdarrays of matching shape.

arkouda.numpy.numeric.where(condition: arkouda.numpy.pdarrayclass.pdarray, A: str | arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings | arkouda.pandas.categorical.Categorical, B: str | arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings | arkouda.pandas.categorical.Categorical) arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings | arkouda.pandas.categorical.Categorical[source]

Return 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, bool, 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

>>> import arkouda as ak
>>> 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