Array#

class ivy.data_classes.array.array.Array(data, dynamic_backend=None)[source]#

Bases: _ArrayWithActivations, _ArrayWithCreation, _ArrayWithDataTypes, _ArrayWithDevice, _ArrayWithElementwise, _ArrayWithGeneral, _ArrayWithGradients, _ArrayWithImage, _ArrayWithLayers, _ArrayWithLinearAlgebra, _ArrayWithLosses, _ArrayWithManipulation, _ArrayWithNorms, _ArrayWithRandom, _ArrayWithSearching, _ArrayWithSet, _ArrayWithSorting, _ArrayWithStatistical, _ArrayWithUtility, _ArrayWithActivationsExperimental, _ArrayWithConversionsExperimental, _ArrayWithCreationExperimental, _ArrayWithData_typeExperimental, _ArrayWithDeviceExperimental, _ArrayWithElementWiseExperimental, _ArrayWithGeneralExperimental, _ArrayWithGradientsExperimental, _ArrayWithImageExperimental, _ArrayWithLayersExperimental, _ArrayWithLinearAlgebraExperimental, _ArrayWithLossesExperimental, _ArrayWithManipulationExperimental, _ArrayWithNormsExperimental, _ArrayWithRandomExperimental, _ArrayWithSearchingExperimental, _ArrayWithSetExperimental, _ArrayWithSortingExperimental, _ArrayWithStatisticalExperimental, _ArrayWithUtilityExperimental

property T: Array#

Transpose of the array.

Returns:

ret – two-dimensional array whose first and last dimensions (axes) are permuted in reverse order relative to original array.

__abs__()[source]#

ivy.Array special method variant of ivy.abs. This method simply wraps the function, and so the docstring for ivy.abs also applies to this method with minimal changes.

Parameters:

self – input array. Should have a numeric data type.

Returns:

ret – an array containing the absolute value of each element in self. The returned array must have the same data type as self.

Examples

With ivy.Array input:

>>> x = ivy.array([6, -2, 0, -1])
>>> print(abs(x))
ivy.array([6, 2, 0, 1])
>>> x = ivy.array([-1.2, 1.2])
>>> print(abs(x))
ivy.array([1.2, 1.2])
__add__(other)[source]#

ivy.Array special method variant of ivy.add. This method simply wraps the function, and so the docstring for ivy.add also applies to this method with minimal changes.

Parameters:
  • self – first input array. Should have a numeric data type.

  • other – second input array. Must be compatible with self (see broadcasting). Should have a numeric data type.

Returns:

ret – an array containing the element-wise sums. The returned array must have a data type determined by type-promotion.

Examples

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.array([4, 5, 6])
>>> z = x + y
>>> print(z)
ivy.array([5, 7, 9])
__eq__(other)[source]#

ivy.Array special method variant of ivy.equal. This method simply wraps the function, and so the docstring for ivy.equal also applies to this method with minimal changes.

Parameters:
  • self – first input array. May have any data type.

  • other – second input array. Must be compatible with x1 (with Broadcasting). May have any data type.

Returns:

ret – an array containing the element-wise results. The returned array must have a data type of bool.

Examples

With ivy.Array instances:

>>> x1 = ivy.array([1, 0, 1, 1])
>>> x2 = ivy.array([1, 0, 0, -1])
>>> y = x1 == x2
>>> print(y)
ivy.array([True, True, False, False])
>>> x1 = ivy.array([1, 0, 1, 0])
>>> x2 = ivy.array([0, 1, 0, 1])
>>> y = x1 == x2
>>> print(y)
ivy.array([False, False, False, False])
__ge__(other)[source]#

ivy.Array special method variant of ivy.greater_equal. This method simply wraps the function, and so the docstring for ivy.bitwise_xor also applies to this method with minimal changes.

Parameters:
  • self – first input array. May have any data type.

  • other – second input array. Must be compatible with x1 (with Broadcasting). May have any data type.

Returns:

ret – an array containing the element-wise results. The returned array must have a data type of bool.

Examples

With ivy.Array instances:

>>> x = ivy.array([6, 2, 3])
>>> y = ivy.array([4, 5, 6])
>>> z = x >= y
>>> print(z)
ivy.array([True,False,False])

With mix of ivy.Array and ivy.Container instances:

>>> x = ivy.array([[5.1, 2.3, -3.6]])
>>> y = ivy.Container(a=ivy.array([[4.], [5.1], [6.]]),b=ivy.array([[5.], [6.], [7.]]))
>>> z = x >= y
>>> print(z)
{
    a: ivy.array([[True, False, False],
                  [True, False, False],
                  [False, False, False]]),
    b: ivy.array([[True, False, False],
                  [False, False, False],
                  [False, False, False]])
}
__gt__(other)[source]#

ivy.Array special method variant of ivy.greater. This method simply wraps the function, and so the docstring for ivy.greater also applies to this method with minimal changes.

Parameters:
  • self – first input array. May have any data type.

  • other – second input array. Must be compatible with x1 (with Broadcasting). May have any data type.

Returns:

ret – an array containing the element-wise results. The returned array must have a data type of bool.

Examples

With ivy.Array instances:

>>> x = ivy.array([6, 2, 3])
>>> y = ivy.array([4, 5, 3])
>>> z = x > y
>>> print(z)
ivy.array([True,False,False])

With mix of ivy.Array and ivy.Container instances:

>>> x = ivy.array([[5.1, 2.3, -3.6]])
>>> y = ivy.Container(a=ivy.array([[4.], [5.1], [6.]]),b=ivy.array([[-3.6], [6.], [7.]]))
>>> z = x > y
>>> print(z)
{
    a: ivy.array([[True, False, False],
                  [False, False, False],
                  [False, False, False]]),
    b: ivy.array([[True, True, False],
                  [False, False, False],
                  [False, False, False]])
}
__init__(data, dynamic_backend=None)[source]#
__le__(other)[source]#

ivy.Array special method variant of ivy.less_equal. This method simply wraps the function, and so the docstring for ivy.less_equal also applies to this method with minimal changes.

Parameters:
  • self – first input array. May have any data type.

  • other – second input array. Must be compatible with x1 (with Broadcasting). May have any data type.

Returns:

ret – an array containing the element-wise results. The returned array must have a data type of bool.

Examples

>>> x = ivy.array([6, 2, 3])
>>> y = ivy.array([4, 5, 3])
>>> z = x <= y
>>> print(z)
ivy.array([ False, True, True])
__lt__(other)[source]#

ivy.Array special method variant of ivy.less. This method simply wraps the function, and so the docstring for ivy.less also applies to this method with minimal changes.

Parameters:
  • self – first input array. May have any data type.

  • other – second input array. Must be compatible with x1 (with Broadcasting). May have any data type.

Returns:

ret – an array containing the element-wise results. The returned array must have a data type of bool.

Examples

>>> x = ivy.array([6, 2, 3])
>>> y = ivy.array([4, 5, 3])
>>> z = x < y
>>> print(z)
ivy.array([ False, True, False])
__ne__(other)[source]#

ivy.Array special method variant of ivy.not_equal. This method simply wraps the function, and so the docstring for ivy.not_equal also applies to this method with minimal changes.

Parameters:
  • self – first input array. May have any data type.

  • other – second input array. Must be compatible with x1 (with Broadcasting). May have any data type.

Returns:

ret – an array containing the element-wise results. The returned array must have a data type of bool.

Examples

With ivy.Array instances:

>>> x1 = ivy.array([1, 0, 1, 1])
>>> x2 = ivy.array([1, 0, 0, -1])
>>> y = x1 != x2
>>> print(y)
ivy.array([False, False, True, True])
>>> x1 = ivy.array([1, 0, 1, 0])
>>> x2 = ivy.array([0, 1, 0, 1])
>>> y = x1 != x2
>>> print(y)
ivy.array([True, True, True, True])
__pow__(power)[source]#

ivy.Array special method variant of ivy.pow. This method simply wraps the function, and so the docstring for ivy.pow also applies to this method with minimal changes.

Parameters:
  • self – Input array or float.

  • power – Array or float power. Must be compatible with self (see broadcasting). Should have a numeric data type.

Returns:

ret – an array containing the element-wise sums. The returned array must have a data type determined by type-promotion.

Examples

With ivy.Array input:

>>> x = ivy.array([1, 2, 3])
>>> y = x ** 2
>>> print(y)
ivy.array([1, 4, 9])
>>> x = ivy.array([1.2, 2.1, 3.5])
>>> y = x ** 2.9
>>> print(y)
ivy.array([ 1.69678056,  8.59876156, 37.82660675])
__radd__(other)[source]#

ivy.Array reverse special method variant of ivy.add. This method simply wraps the function, and so the docstring for ivy.add also applies to this method with minimal changes.

Parameters:
  • self – first input array. Should have a numeric data type.

  • other – second input array. Must be compatible with self (see broadcasting). Should have a numeric data type.

Returns:

ret – an array containing the element-wise sums. The returned array must have a data type determined by type-promotion.

Examples

>>> x = 1
>>> y = ivy.array([4, 5, 6])
>>> z = x + y
>>> print(z)
ivy.array([5, 6, 7])
__rrshift__(other)[source]#

ivy.Array reverse special method variant of ivy.bitwise_right_shift. This method simply wraps the function, and so the docstring for ivy.bitwise_right_shift also applies to this method with minimal changes.

Parameters:
  • self – first input array. Should have an integer data type.

  • other – second input array. Must be compatible with x1 (see broadcasting). Should have an integer data type. Each element must be greater than or equal to 0.

Returns:

ret – an array containing the element-wise results. The returned array must have a data type determined by type-promotion.

Examples

>>> a = 32
>>> b = ivy.array([0, 1, 2])
>>> y = a >> b
>>> print(y)
ivy.array([32, 16,  8])
__rshift__(other)[source]#

ivy.Array special method variant of ivy.bitwise_right_shift. This method simply wraps the function, and so the docstring for ivy.bitwise_right_shift also applies to this method with minimal changes.

Parameters:
  • self – first input array. Should have an integer data type.

  • other – second input array. Must be compatible with x1 (see broadcasting). Should have an integer data type. Each element must be greater than or equal to 0.

Returns:

ret – an array containing the element-wise results. The returned array must have a data type determined by type-promotion.

Examples

With ivy.Array instances only:

>>> a = ivy.array([2, 3, 4])
>>> b = ivy.array([0, 1, 2])
>>> y = a >> b
>>> print(y)
ivy.array([2, 1, 1])
__rsub__(other)[source]#

ivy.Array reverse special method variant of ivy.subtract. This method simply wraps the function, and so the docstring for ivy.subtract also applies to this method with minimal changes.

Parameters:
  • self – first input array. Should have a numeric data type.

  • other – second input array. Must be compatible with self (see broadcasting). Should have a numeric data type.

Returns:

ret – an array containing the element-wise differences. The returned array must have a data type determined by type-promotion.

Examples

>>> x = 1
>>> y = ivy.array([4, 5, 6])
>>> z = x - y
>>> print(z)
ivy.array([-3, -4, -5])
__sub__(other)[source]#

ivy.Array special method variant of ivy.subtract. This method simply wraps the function, and so the docstring for ivy.subtract also applies to this method with minimal changes.

Parameters:
  • self – first input array. Should have a numeric data type.

  • other – second input array. Must be compatible with self (see broadcasting). Should have a numeric data type.

Returns:

ret – an array containing the element-wise differences. The returned array must have a data type determined by type-promotion.

Examples

With ivy.Array instances only:

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.array([4, 5, 6])
>>> z = x - y
>>> print(z)
ivy.array([-3, -3, -3])
__truediv__(other)[source]#

ivy.Array reverse special method variant of ivy.divide. This method simply wraps the function, and so the docstring for ivy.divide also applies to this method with minimal changes.

Parameters:
  • self – first input array. Should have a numeric data type.

  • other – second input array. Must be compatible with self (see broadcasting). Should have a numeric data type.

Returns:

ret – an array containing the element-wise results. The returned array must have a data type determined by type-promotion.

Examples

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.array([4, 5, 6])
>>> z = x / y
>>> print(z)
ivy.array([0.25      , 0.40000001, 0.5       ])
__xor__(other)[source]#

ivy.Array special method variant of ivy.bitwise_xor. This method simply wraps the function, and so the docstring for ivy.bitwise_xor also applies to this method with minimal changes.

Parameters:
  • self – first input array. Should have an integer or boolean data type.

  • other – second input array. Must be compatible with x1 (see broadcasting). Should have an integer or boolean data type.

  • out – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Returns:

ret – an array containing the element-wise results. The returned array must have a data type determined by type-promotion.

Examples

With ivy.Array instances:

>>> a = ivy.array([1, 2, 3])
>>> b = ivy.array([3, 2, 1])
>>> y = a ^ b
>>> print(y)
ivy.array([2,0,2])

With mix of ivy.Array and ivy.Container instances:

>>> x = ivy.Container(a = ivy.array([-67, 21]))
>>> y = ivy.array([12, 13])
>>> z = x ^ y
>>> print(z)
{a: ivy.array([-79, 24])}
property backend#
property base: Array#

Original array referenced by view.

property data: NativeArray#

The native array being wrapped in self.

property device: Device#

Hardware device the array data resides on.

property dtype: Dtype#

Data type of the array elements.

property dynamic_backend#
property imag: Array#

Imaginary part of the array.

Returns:

ret – array containing the imaginary part of each element in the array. The returned array must have the same shape and data type as the original array.

property itemsize: int | None#

Size of array elements in bytes.

property mT: Array#

Transpose of a matrix (or a stack of matrices).

Returns:

ret – array whose last two dimensions (axes) are permuted in reverse order relative to original array (i.e., for an array instance having shape (..., M, N), the returned array must have shape (..., N, M)). The returned array must have the same data type as the original array.

property ndim: int#

Number of array dimensions (axes).

property real: Array#

Real part of the array.

Returns:

ret – array containing the real part of each element in the array. The returned array must have the same shape and data type as the original array.

property shape: Shape#

Array dimensions.

property size: int | None#

Number of elements in the array.

property strides: int | None#

Get strides across each dimension.

This should have hopefully given you an overview of the array submodule, if you have any questions, please feel free to reach out on our discord!