Array class

The main data structure in pyclesperanto is the Array class which behave similar to numpy arrays, but point to a memory location on the device. Here is a collection of class functions, operators, and methods to work with Array objects. Mainly to create, manipulate, and transfer them, as well as to apply arythmetic and logical operations on them.

T(self)[source]

Transpose the Array. Only works for 2D and 3D arrays.

empty(cls, shape, dtype=<class 'float'>, *args, **kwargs)[source]

Create an empty Array object from a shape.

Parameters:
  • shape (tuple, list or np.ndarray) – The shape of the array, maximum 3 elements.

  • dtype (np.dtype, default float) – The dtype of the array.

  • mtype (str, optional) – The memory type, by default “buffer”

  • device (Device, optional) – The device, by default None

Returns:

A new Array object.

Return type:

Array

empty_like(cls, arr)[source]

Create an empty Array object from an other array.

Parameters:

arr (np.ndarray or Array or other array-like structure) – The array to create like.

Returns:

The created array.

Return type:

Array

from_array(cls, arr, *args, **kwargs)[source]

Create an Array object from a numpy array (same shape, dtype, and memory).

Parameters:
  • arr (np.ndarray) – The array to convert.

  • mtype (str, optional) – The memory type, by default “buffer”

  • device (Device, optional) – The device, by default None

Returns:

The converted array.

Return type:

Array

get(self, origin: tuple | None = None, region: tuple | None = None) ndarray[source]

Get the content of the Array into a numpy array.

Parameters:
  • origin (tuple, optional) – The origin of the region of interest, by default None

  • region (tuple, optional) – The region of interest, by default None

Returns:

The array itself.

Return type:

np.ndarray

is_image(object)[source]

Returns True if the given object is an image.

reshape(self, shape)[source]

Reshape the Array.

set(self, array: ndarray, origin: tuple | None = None, region: tuple | None = None) None[source]

Set the content of the Array to the given numpy array.

Parameters:
  • array (np.ndarray) – The array to set from.

  • origin (tuple, optional) – The origin of the region of interest, by default None

  • region (tuple, optional) – The region of interest, by default None

Returns:

The array itself.

Return type:

Array

to_device(cls, arr, *args, **kwargs)[source]

Create an Array object from a numpy array (same shape, dtype, and memory).

Parameters:
  • arr (np.ndarray) – The array to convert.

  • mtype (str, optional) – The memory type, by default “buffer”

  • device (Device, optional) – The device, by default None

Returns:

The converted array.

Return type:

Array

zeros(cls, shape, dtype=<class 'float'>, *args, **kwargs)[source]

Create an Array object full of zeros from a shape.

Parameters:
  • shape (tuple, list or np.ndarray) – The shape of the array, maximum 3 elements.

  • dtype (np.dtype, default float) – The dtype of the array.

  • mtype (str, optional) – The memory type, by default “buffer”

  • device (Device, optional) – The device, by default None

Returns:

The created array.

Return type:

Array

zeros_like(cls, arr)[source]

Create an Array object filled with zeros from an other array.

Parameters:

arr (np.ndarray or Array or other array-like structure) – The array to create like.

Returns:

The created array.

Return type:

Array