ArrayView in Arkouda

class arkouda.ArrayView(base, shape, order='row_major')[source]

A multi-dimensional view of a pdarray. Arkouda ArraryView behaves similarly to numpy’s ndarray. The base pdarray is stored in 1-dimension but can be indexed and treated logically as if it were multi-dimensional

base

The base pdarray that is being viewed as a multi-dimensional object

Type:

pdarray

dtype

The element type of the base pdarray (equivalent to base.dtype)

Type:

dtype

size

The number of elements in the base pdarray (equivalent to base.size)

Type:

int_scalars

shape

A pdarray specifying the sizes of each dimension of the array

Type:

pdarray[int]

ndim

Number of dimensions (equivalent to shape.size)

Type:

int_scalars

itemsize

The size in bytes of each element (equivalent to base.itemsize)

Type:

int_scalars

order

Index order to read and write the elements. By default or if ‘C’/’row_major’, read and write data in row_major order If ‘F’/’column_major’, read and write data in column_major order

Type:

str {‘C’/’row_major’ | ‘F’/’column_major’}

Creation

ArrayViews can be created using ak.array or pdarray.reshape

>>> ak.array([[0, 0], [0, 1], [1, 1]])
array([[0, 0],
       [0, 1],
       [1, 1]])

>>> ak.arange(30).reshape(5, 2, 3)
array([[[ 0,  1,  2],
        [ 3,  4,  5]],

       [[ 6,  7,  8],
        [ 9, 10, 11]],

       [[12, 13, 14],
        [15, 16, 17]],

       [[18, 19, 20],
        [21, 22, 23]],

       [[24, 25, 26],
        [27, 28, 29]]])

Indexing

Arkouda ArrayView objects support basic indexing

  • Indexing with an integer pdarray (of size ndim) or

  • Indexing with a mix of integers and slices

Mixed indexing by arrays or “advanced indexing” as numpy calls it is not yet supported. numpy behavior with 2+ arrays is different than equivalent slices.

This example shows how indexing by arrays can be a bit different. This is talked about a bit in https://numpy.org/doc/stable/user/basics.indexing.html

>>> n = np.arange(4).reshape(2,2)
# sometimes they line up
>>> n[:,:]
array([[0, 1],
       [2, 3]])

>>> n[:,[0,1]]
array([[0, 1],
       [2, 3]])

>>> n[[0,1],:]
array([[0, 1],
       [2, 3]])
# sometimes they do not
>>> n[[0,1],[0,1]]
array([0, 3])

With 2+ arrays the functionality switches from the Cartesian product of coordinates to more coordinate-wise.

so n[:, :] gets indices [0,0], [0,1], [1,0], [1,1] whereas n[[0,1],[0,1]] only gets indices [0,0], [1,1]

Iteration

Iterating directly over an ArrayView with for x in array_view is not supported to discourage transferring all array data from the arkouda server to the Python client. To force this transfer, use the to_ndarray function to return the ArrayView as a numpy.ndarray. This transfer will raise an error if it exceeds the byte limit defined in ak.client.maxTransferBytes.

arkouda.ArrayView.to_ndarray(self)

Convert the ArrayView to a np.ndarray, transferring array data from the Arkouda server to client-side Python. Note: if the ArrayView size exceeds client.maxTransferBytes, a RuntimeError is raised.

Returns:

A numpy ndarray with the same attributes and data as the ArrayView

Return type:

np.ndarray

Raises:

RuntimeError – Raised if there is a server-side error thrown, if the ArrayView size exceeds the built-in client.maxTransferBytes size limit, or if the bytes received does not match expected number of bytes

Notes

The number of bytes in the array cannot exceed client.maxTransferBytes, otherwise a RuntimeError will be raised. This is to protect the user from overflowing the memory of the system on which the Python client is running, under the assumption that the server is running on a distributed system with much more memory than the client. The user may override this limit by setting client.maxTransferBytes to a larger value, but proceed with caution.

See also

array, to_list

Examples

>>> a = ak.arange(6).reshape(2,3)
>>> a.to_ndarray()
array([[0, 1, 2],
       [3, 4, 5]])
>>> type(a.to_ndarray())
numpy.ndarray