arkouda.numpy.manipulation_functions

Functions

flip(…)

Reverse an array's values along a particular axis or axes.

repeat(→ arkouda.numpy.pdarrayclass.pdarray)

Repeat each element of an array after themselves.

squeeze(→ arkouda.numpy.pdarrayclass.pdarray)

Remove degenerate (size one) dimensions from an array.

tile(→ arkouda.numpy.pdarrayclass.pdarray)

Construct an array by repeating A the number of times given by reps.

Module Contents

arkouda.numpy.manipulation_functions.flip(x: arkouda.numpy.pdarrayclass.pdarray, /, *, axis: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | None = None) arkouda.numpy.pdarrayclass.pdarray[source]
arkouda.numpy.manipulation_functions.flip(x: arkouda.numpy.strings.Strings, /, *, axis: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | None = None) arkouda.numpy.strings.Strings
arkouda.numpy.manipulation_functions.flip(x: arkouda.pandas.categorical.Categorical, /, *, axis: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | None = None) arkouda.pandas.categorical.Categorical

Reverse an array’s values along a particular axis or axes.

Parameters:
  • x (pdarray, Strings, or Categorical) –

    Reverse the order of elements in an array along the given axis.

    The shape of the array is preserved, but the elements are reordered.

  • axis (int or Tuple[int, ...], optional) – The axis or axes along which to flip the array. If None, flip the array along all axes.

Returns:

An array with the entries of axis reversed.

Return type:

pdarray, Strings, or Categorical

Raises:

IndexError – Raised if operation fails server-side.

Examples

>>> import arkouda as ak
>>> a = ak.arange(12)
>>> ak.flip(a)
array([11 10 9 8 7 6 5 4 3 2 1 0])

Note

This differs from numpy as it actually reverses the data, rather than presenting a view.

arkouda.numpy.manipulation_functions.repeat(a: int | Sequence[int] | arkouda.numpy.pdarrayclass.pdarray, repeats: int | Sequence[int] | arkouda.numpy.pdarrayclass.pdarray, axis: None | int = None) arkouda.numpy.pdarrayclass.pdarray[source]

Repeat each element of an array after themselves.

Parameters:
  • a (int, Sequence of int, or pdarray) – Input array.

  • repeats (int, Sequence of int, or pdarray) – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.

  • axis (int, optional) – The axis along which to repeat values. By default, use the flattened input array, and return a flat output array.

Returns:

Output array which has the same shape as a, except along the given axis.

Return type:

pdarray

Raises:
  • ValueError – Raised if repeats is not an int or a 1-dimensional array, or if it contains negative values, if its size does not match the input arrays size along axis.

  • RuntimeError – Raised if the operation fails server-side.

  • TypeError – Raised if axis anything but None or int, or if either a or repeats is invalid (the a and repeat cases should be impossible).

  • IndexError – Raised if axis is invalid for the given rank.

Examples

>>> import arkouda as ak
>>> ak.repeat(3, 4)
array([3 3 3 3])
>>> x = ak.array([[1,2],[3,4]])
>>> ak.repeat(x, 2)
array([1 1 2 2 3 3 4 4])
>>> ak.repeat(x, 3, axis=1)
array([array([1 1 1 2 2 2]) array([3 3 3 4 4 4])])
>>> ak.repeat(x, [1, 2], axis=0)
array([array([1 2]) array([3 4]) array([3 4])])
arkouda.numpy.manipulation_functions.squeeze(x: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.dtypes.bool_scalars, /, axis: None | arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] = None) arkouda.numpy.pdarrayclass.pdarray[source]

Remove degenerate (size one) dimensions from an array.

Parameters:
  • x (pdarray) – The array to squeeze

  • axis (int or Tuple[int, ...]) – The axis or axes to squeeze (must have a size of one). If axis = None, all dimensions of size 1 will be squeezed.

Returns:

A copy of x with the dimensions specified in the axis argument removed.

Return type:

pdarray

Raises:

RuntimeError – Raised if operation fails server-side.

Examples

>>> import arkouda as ak
>>> x = ak.arange(10).reshape((1, 10, 1))
>>> x.shape
(1, 10, 1)
>>> ak.squeeze(x, axis=None).shape
(10,)
>>> ak.squeeze(x, axis=2).shape
(1, 10)
>>> ak.squeeze(x, axis=(0, 2)).shape
(10,)
arkouda.numpy.manipulation_functions.tile(A: arkouda.numpy.pdarrayclass.pdarray, /, reps: int | Tuple[int, Ellipsis]) arkouda.numpy.pdarrayclass.pdarray[source]

Construct an array by repeating A the number of times given by reps.

If reps has length d, the result will have dimension of max(d, A.ndim).

If A.ndim < d, A is promoted to be d-dimensional by prepending new axes. So a shape (3,) array is promoted to (1, 3) for 2-D replication, or shape (1, 1, 3) for 3-D replication. If this is not the desired behavior, promote A to d-dimensions manually before calling this function.

If A.ndim > d, reps is promoted to A.ndim by prepending 1’s to it. Thus for an A of shape (2, 3, 4, 5), a reps of (2, 2) is treated as (1, 1, 2, 2).

Parameters:
  • A (pdarray) – The input pdarray to be tiled

  • reps (int or Tuple of int) – The number of repetitions of A along each axis.

Returns:

A new pdarray with the tiled data.

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> a = ak.array([0, 1, 2])
>>> ak.tile(a, 2)
array([0 1 2 0 1 2])
>>> ak.tile(a, (2, 2))
array([array([0 1 2 0 1 2]) array([0 1 2 0 1 2])])
>>> ak.tile(a, (2, 1, 2))
array([array([array([0 1 2 0 1 2])]) array([array([0 1 2 0 1 2])])])
>>> b = ak.array([[1, 2], [3, 4]])
>>> ak.tile(b, 2)
array([array([1 2 1 2]) array([3 4 3 4])])
>>> ak.tile(b, (2, 1))
array([array([1 2]) array([3 4]) array([1 2]) array([3 4])])
>>> c = ak.array([1, 2, 3, 4])
>>> ak.tile(c, (4, 1))
array([array([1 2 3 4]) array([1 2 3 4]) array([1 2 3 4]) array([1 2 3 4])])