arkouda.numpy.pdarraymanipulation

Functions

append(→ arkouda.numpy.pdarrayclass.pdarray)

Append values to the end of an array.

delete(→ arkouda.numpy.pdarrayclass.pdarray)

Return a copy of 'arr' with elements along the specified axis removed.

hstack(→ arkouda.numpy.pdarrayclass.pdarray)

Stack arrays in sequence horizontally (column wise).

vstack(→ arkouda.numpy.pdarrayclass.pdarray)

Stack arrays in sequence vertically (row wise).

Module Contents

arkouda.numpy.pdarraymanipulation.append(arr: arkouda.numpy.pdarrayclass.pdarray, values: arkouda.numpy.pdarrayclass.pdarray, axis: int | None = None) arkouda.numpy.pdarrayclass.pdarray[source]

Append values to the end of an array.

Parameters:
  • arr (pdarray) – Values are appended to a copy of this array.

  • values (pdarray) – These values are appended to a copy of arr. It must be of the correct shape (the same shape as arr, excluding axis). If axis is not specified, values can be any shape and will be flattened before use.

  • axis (Optional[int], default=None) – The axis along which values are appended. If axis is not given, both arr and values are flattened before use.

Returns:

A copy of arr with values appended to axis. Note that append does not occur in-place: a new array is allocated and filled. If axis is None, out is a flattened array.

Return type:

pdarray

See also

delete

Examples

>>> import arkouda as ak
>>> a = ak.array([1, 2, 3])
>>> b = ak.array([[4, 5, 6], [7, 8, 9]])
>>> ak.append(a, b)
array([1 2 3 4 5 6 7 8 9])
>>> ak.append(b, b, axis = 0)
array([array([4 5 6]) array([7 8 9]) array([4 5 6]) array([7 8 9])])
arkouda.numpy.pdarraymanipulation.delete(arr: arkouda.numpy.pdarrayclass.pdarray, obj: slice | int | Sequence[int] | Sequence[bool] | arkouda.numpy.pdarrayclass.pdarray, axis: int | None = None) arkouda.numpy.pdarrayclass.pdarray[source]

Return a copy of ‘arr’ with elements along the specified axis removed.

Parameters:
  • arr (pdarray) – The array to remove elements from

  • obj (slice, int, Sequence of int, Sequence of bool, or pdarray) – The indices to remove from ‘arr’. If obj is a pdarray, it must have an integer or bool dtype.

  • axis (Optional[int], optional) – The axis along which to remove elements. If None, the array will be flattened before removing elements. Defaults to None.

Returns:

A copy of ‘arr’ with elements removed

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> arr = ak.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
>>> arr
array([array([1 2 3 4]) array([5 6 7 8]) array([9 10 11 12])])
>>> ak.delete(arr, 1, 0)
array([array([1 2 3 4]) array([9 10 11 12])])
>>> ak.delete(arr, slice(0, 4, 2), 1)
array([array([2 4]) array([6 8]) array([10 12])])
>>> ak.delete(arr, [1, 3, 5], None)
array([1 3 5 7 8 9 10 11 12])
arkouda.numpy.pdarraymanipulation.hstack(tup: Sequence[arkouda.numpy.pdarrayclass.pdarray], *, dtype: str | type | None = None, casting: Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'] = 'same_kind') arkouda.numpy.pdarrayclass.pdarray[source]

Stack arrays in sequence horizontally (column wise).

This is equivalent to concatenation along the second axis, except for 1-D arrays where it concatenates along the first axis. Rebuilds arrays divided by hsplit.

This function makes most sense for arrays with up to 3 dimensions. For instance, for pixel-data with a height (first axis), width (second axis), and r/g/b channels (third axis). The functions concatenate, stack and block provide more general stacking and concatenation operations.

Parameters:
  • tup (sequence of pdarray) – The arrays must have the same shape along all but the second axis, except 1-D arrays which can be any length. In the case of a single array_like input, it will be treated as a sequence of arrays; i.e., each element along the zeroth axis is treated as a separate array.

  • dtype (str or type, optional) – If provided, the destination array will have this type.

  • casting ({‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional) – Controls what kind of data casting may occur. Defaults to ‘same_kind’. Currently unused.

Returns:

The array formed by stacking the given arrays.

Return type:

pdarray

See also

concatenate, stack, block, vstack, dstack, column_stack, hsplit, unstack

Examples

>>> import arkouda as ak
>>> a = ak.array([1, 2, 3])
>>> b = ak.array([4, 5, 6])
>>> ak.hstack((a, b))
array([1 2 3 4 5 6])
>>> a = ak.array([[1],[2],[3]])
>>> b = ak.array([[4],[5],[6]])
>>> ak.hstack((a, b))
array([array([1 4]) array([2 5]) array([3 6])])
arkouda.numpy.pdarraymanipulation.vstack(tup: Sequence[arkouda.numpy.pdarrayclass.pdarray], *, dtype: str | type | None = None, casting: Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'] = 'same_kind') arkouda.numpy.pdarrayclass.pdarray[source]

Stack arrays in sequence vertically (row wise).

This is equivalent to concatenation along the first axis after 1-D arrays of shape (N,) have been reshaped to (1,N). Rebuilds arrays divided by vsplit.

This function makes most sense for arrays with up to 3 dimensions. For instance, for pixel-data with a height (first axis), width (second axis), and r/g/b channels (third axis). The functions concatenate, stack and block provide more general stacking and concatenation operations.

Parameters:
  • tup (sequence of pdarray) – The arrays must have the same shape along all but the first axis. 1-D arrays must have the same length. In the case of a single array_like input, it will be treated as a sequence of arrays; i.e., each element along the zeroth axis is treated as a separate array.

  • dtype (str or type, optional) – If provided, the destination array will have this dtype.

  • casting ({"no", "equiv", "safe", "same_kind", "unsafe"], optional) – Controls what kind of data casting may occur. Defaults to ‘same_kind’. Currently unused.

Returns:

The array formed by stacking the given arrays, will be at least 2-D.

Return type:

pdarray

See also

concatenate, stack, block, hstack, dstack, column_stack, hsplit, unstack

Examples

>>> import arkouda as ak
>>> a = ak.array([1, 2, 3])
>>> b = ak.array([4, 5, 6])
>>> ak.vstack((a, b))
array([array([1 2 3]) array([4 5 6])])
>>> a = ak.array([[1],[2],[3]])
>>> b = ak.array([[4],[5],[6]])
>>> ak.vstack((a, b))
array([array([1]) array([2]) array([3]) array([4]) array([5]) array([6])])