General#

class ivy.data_classes.array.general._ArrayWithGeneral[source]#

Bases: ABC

_abc_impl = <_abc._abc_data object>#
all_equal(*x2, equality_matrix=False)[source]#

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

Parameters:
  • self (Array) – input array

  • x2 (Iterable[Any]) – input iterable to compare to self

  • equality_matrix (bool, default: False) – Whether to return a matrix of equalities comparing each input with every other. Default is False.

Return type:

Union[bool, Array, NativeArray]

Returns:

ret – Boolean, whether or not the inputs are equal, or matrix array of booleans if equality_matrix=True is set.

Examples

>>> x1 = ivy.array([1, 1, 0, 0, 1, -1])
>>> x2 = ivy.array([1, 1, 0, 0, 1, -1])
>>> y = x1.all_equal(x2)
>>> print(y)
True
>>> x1 = ivy.array([0, 0])
>>> x2 = ivy.array([0, 0])
>>> x3 = ivy.array([1, 0])
>>> y = x1.all_equal(x2, x3, equality_matrix=True)
>>> print(y)
ivy.array([[ True,  True, False],
   [ True,  True, False],
   [False, False,  True]])
array_equal(x, /)[source]#

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

Parameters:
  • self (Array) – input array

  • x (Union[Array, NativeArray]) – input array to compare to self

Return type:

bool

Returns:

ret – Boolean, whether or not the input arrays are equal

Examples

>>> x = ivy.array([-1,0])
>>> y = ivy.array([1,0])
>>> z = x.array_equal(y)
>>> print(z)
False
>>> a = ivy.array([1, 2])
>>> b = ivy.array([1, 2])
>>> c = a.array_equal(b)
>>> print(c)
True
>>> i = ivy.array([1, 2])
>>> j = ivy.array([1, 2, 3])
>>> k = i.array_equal(j)
>>> print(k)
False
assert_supports_inplace()[source]#

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

Parameters:

self (Array) – input array

Return type:

bool

Returns:

ret – True if supports, raises IvyBackendException otherwise

Examples

With ivy.Array input and default backend set as torch:

>>> ivy.set_backend("torch")
>>> x = ivy.array([1, 2, 3])
>>> print(x.assert_supports_inplace())
True

With ivy.Array input and default backend set as numpy:

>>> ivy.set_backend("numpy")
>>> x = ivy.array([1, 2, 3])
>>> print(x.assert_supports_inplace())
True
clip_matrix_norm(max_norm, /, *, p=2.0, out=None)[source]#

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

Parameters:
  • self (Array) – input array

  • max_norm (float) – The maximum value of the array norm.

  • p (float, default: 2.0) – The p-value for computing the p-norm. Default is 2.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – An array with the matrix norm downscaled to the max norm if needed.

Examples

With ivy.Array instance method:

>>> x = ivy.array([[0., 1., 2.]])
>>> y = x.clip_matrix_norm(2.0)
>>> print(y)
ivy.array([[0.   , 0.894, 1.79 ]])
clip_vector_norm(max_norm, /, *, p=2.0, out=None)[source]#

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

Parameters:
  • self (Array) – input array

  • max_norm (float) – float, the maximum value of the array norm.

  • p (float, default: 2.0) – optional float, the p-value for computing the p-norm. Default is 2.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – An array with the vector norm downscaled to the max norm if needed.

Examples

With ivy.Array instance method:

>>> x = ivy.array([0., 1., 2.])
>>> y = x.clip_vector_norm(2.0)
>>> print(y)
ivy.array([0., 0.894, 1.79])
default(default_val, *, catch_exceptions=False, rev=False, with_callable=False)[source]#

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

Parameters:
  • self (Array) – input array

  • default_val (Any) – The default value.

  • catch_exceptions (bool, default: False) – Whether to catch exceptions from callable x. Default is False.

  • rev (bool, default: False) – Whether to reverse the input x and default_val. Default is False.

  • with_callable (bool, default: False) – Whether either of the arguments might be callable functions. Default is False.

Return type:

Any

Returns:

ret – x if x exists (is not None), else default.

Examples

>>> x = ivy.array([1, 2, 3, 1.2])
>>> y = x.default(0)
>>> print(y)
ivy.array([1. , 2. , 3. , 1.2])
einops_rearrange(pattern, /, *, out=None, **axes_lengths)[source]#

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

Parameters:
  • self (Array) – Input array to be re-arranged.

  • pattern (str) – Rearrangement pattern.

  • axes_lengths (Dict[str, int]) – Any additional specifications for dimensions.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – New array with einops.rearrange having been applied.

Examples

With ivy.Array instance method:

>>> x = ivy.array([[1, 2, 3],
...               [-4, -5, -6]])
>>> y = x.einops_rearrange("height width -> width height")
>>> print(y)
ivy.array([[ 1, -4],
    [ 2, -5],
    [ 3, -6]])
>>> x = ivy.array([[[ 1,  2,  3],
...                  [ 4,  5,  6]],
...               [[ 7,  8,  9],
...                  [10, 11, 12]]])
>>> y = x.einops_rearrange("c h w -> c (h w)")
>>> print(y)
ivy.array([[ 1,  2,  3,  4,  5,  6],
    [ 7,  8,  9, 10, 11, 12]])
>>> x = ivy.array([[1, 2, 3, 4, 5, 6]
...               [7, 8, 9, 10, 11, 12]])
>>> y = x.einops_rearrange("c (h w) -> (c h) w", h=2, w=3)
ivy.array([[ 1,  2,  3],
    [ 4,  5,  6],
    [ 7,  8,  9],
    [10, 11, 12]])
einops_reduce(pattern, reduction, /, *, out=None, **axes_lengths)[source]#

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

Parameters:
  • self (Array) – Input array to be reduced.

  • pattern (str) – Reduction pattern.

  • reduction (Union[str, Callable]) – One of available reductions (‘min’, ‘max’, ‘sum’, ‘mean’, ‘prod’), or callable.

  • axes_lengths (Dict[str, int]) – Any additional specifications for dimensions.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – New array with einops.reduce having been applied.

Examples

With ivy.Array inputs:

>>> x = ivy.array([[[5, 4],
...                 [11, 2]],
...                [[3, 5],
...                 [9, 7]]])
>>> reduced = x.einops_reduce('a b c -> b c', 'max')
>>> print(reduced)
ivy.array([[ 5,  5],
           [11,  7]])

With ivy.Array inputs:

>>> x = ivy.array([[[5, 4, 3],
...                 [11, 2, 9]],
...                [[3, 5, 7],
...                 [9, 7, 1]]])
>>> reduced = x.einops_reduce('a b c -> a () c', 'min')
>>> print(reduced)
ivy.array([[[5, 2, 3]],
           [[3, 5, 1]]])
einops_repeat(pattern, /, *, out=None, **axes_lengths)[source]#

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

Parameters:
  • self (Array) – Input array to be repeated.

  • pattern (str) – Rearrangement pattern.

  • axes_lengths (Dict[str, int]) – Any additional specifications for dimensions.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – New array with einops.repeat having been applied.

Examples

With ivy.Array inputs:

>>> x = ivy.array([5,4])
>>> y = x.einops_repeat('a -> a c', c=3)
>>> print(y)
ivy.array([[5, 5, 5],
           [4, 4, 4]])

With ivy.Array inputs:

>>> x = ivy.array([[5,4],
...                [2, 3]])
>>> y = x.einops_repeat('a b ->  a b c', c=3)
>>> print(y)
ivy.array([[[5, 5, 5], [4, 4, 4]], [[2, 2, 2], [3, 3, 3]]])
>>> print(y.shape)
(2, 2, 3)
exists()[source]#

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

Parameters:

self (Array) – input array.

Return type:

bool

Returns:

ret – True if input is not None, else False.

Examples

>>> x = ivy.array([1, 2, 3, 1.2])
>>> y = x.exists()
>>> print(y)
True
>>> x = ivy.array([])
>>> y = x.exists()
>>> print(y)
True
fourier_encode(max_freq, /, *, num_bands=4, linear=False, concat=True, flatten=False)[source]#

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

Parameters:
  • self (Array) – input array to encode

  • max_freq (Union[float, Array, NativeArray]) – The maximum frequency of the encoding.

  • num_bands (int, default: 4) – The number of frequency bands for the encoding. Default is 4.

  • linear (bool, default: False) – Whether to space the frequency bands linearly as opposed to geometrically. Default is False.

  • concat (bool, default: True) – Whether to concatenate the position, sin and cos values, or return separately. Default is True.

  • flatten (bool, default: False) – Whether to flatten the position dimension into the batch dimension. Default is False.

Return type:

Union[Array, NativeArray, Tuple]

Returns:

ret – New array with the final dimension expanded, and the encodings stored in this channel.

Examples

>>> x = ivy.array([1, 2, 3])
>>> y = 1.5
>>> z = x.fourier_encode(y)
>>> print(z)
ivy.array([[ 1.0000000e+00, 1.2246468e-16, 0.0000000e+00, 0.0000000e+00,
             0.0000000e+00, -1.0000000e+00, 1.0000000e+00, 1.0000000e+00,
             1.0000000e+00],
           [ 2.0000000e+00, -2.4492936e-16, 0.0000000e+00, 0.0000000e+00,
             0.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00,
             1.0000000e+00],
           [ 3.0000000e+00, 3.6739404e-16, 0.0000000e+00, 0.0000000e+00,
             0.0000000e+00, -1.0000000e+00, 1.0000000e+00, 1.0000000e+00,
             1.0000000e+00]])
>>> x = ivy.array([3, 10])
>>> y = 2.5
>>> z = x.fourier_encode(y, num_bands=3)
>>> print(z)
ivy.array([[ 3.0000000e+00,  3.6739404e-16,  3.6739404e-16,  3.6739404e-16,
            -1.0000000e+00, -1.0000000e+00, -1.0000000e+00],
           [ 1.0000000e+01, -1.2246468e-15, -1.2246468e-15, -1.2246468e-15,
             1.0000000e+00,  1.0000000e+00,  1.0000000e+00]])
gather(indices, /, *, axis=-1, batch_dims=0, out=None)[source]#

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

Parameters:
  • self (Array) – The array from which to gather values.

  • indices (Union[Array, NativeArray]) – The array which indicates the indices that will be gathered along the specified axis.

  • axis (int, default: -1) – The axis from which the indices will be gathered. Default is -1.

  • batch_dims (int, default: 0) – Optional int, lets you gather different items from each element of a batch. Default is 0.

  • out (Optional[Array], default: None) – Optional array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – New array with the values gathered at the specified indices along the specified axis.

Examples

>>> x = ivy.array([0., 1., 2.])
>>> y = ivy.array([0, 1])
>>> gather = x.gather(y)
>>> print(gather)
ivy.array([0., 1.])
>>> x = ivy.array([[0., 1., 2.],[3., 4., 5.]])
>>> y = ivy.array([[0, 1],[1, 2]])
>>> z = ivy.zeros((2, 2, 2))
>>> gather = x.gather(y, out=z)
>>> print(z)
ivy.array([[[0., 1.],[1., 2.]],[[3., 4.],[4., 5.]]])
>>> x = ivy.array([[[0., 1.], [2., 3.]],
...                [[8., 9.], [10., 11.]]])
>>> y = ivy.array([[0, 1]])
>>> z = ivy.zeros((1, 2, 2, 2))
>>> gather = x.gather(y, axis=0, out=z)
>>> print(z)
ivy.array(
    [[[[ 0.,  1.],
    [ 2.,  3.]],
    [[ 8.,  9.],
    [10., 11.]]]])
>>> x = ivy.array([[0, 10, 20, 0, 0],
...                [0, 0, 0, 30, 40],
...                [0, 10, 0, 0, 40]])
>>> y = ivy.array([[1, 2],[3, 4],[1, 4]])
>>> gather = x.gather(y, batch_dims=1)
>>> print(gather)
ivy.array([[10, 20], [30, 40],[10, 40]])
gather_nd(indices, /, *, batch_dims=0, out=None)[source]#

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

Parameters:
  • self (Array) – The array from which to gather values.

  • indices (Union[Array, NativeArray]) – Index array.

  • batch_dims (int, default: 0) – optional int, lets you gather different items from each element of a batch.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – New array of given shape, with the values gathered at the indices.

Examples

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.array([1])
>>> z = x.gather_nd(y)
>>> print(z)
ivy.array(2)
get_num_dims(*, as_array=False)[source]#

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

Parameters:
  • self (Array) – input array to infer the number of dimensions for

  • as_array (bool, default: False) – Whether to return the shape as a array, default False.

Return type:

int

Returns:

ret – Shape of the array

Examples

>>> x = ivy.array([[0.,1.,1.],[1.,0.,0.],[8.,2.,3.]])
>>> b = x.get_num_dims()
>>> print(b)
2
>>> x = ivy.array([[[0, 0, 0], [0, 0, 0], [0, 0, 0]],                            [[0, 0, 0], [0, 0, 0], [0, 0, 0]],                            [[0, 0, 0], [0, 0, 0], [0, 0, 0]]])
>>> b = x.get_num_dims(as_array=False)
>>> print(b)
3
>>> b = x.get_num_dims(as_array=True)
>>> print(b)
ivy.array(3)
has_nans(*, include_infs=True)[source]#

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

Parameters:
  • self (Array) – input array

  • include_infs (bool, default: True) – Whether to include +infinity and -infinity in the check. Default is True.

Returns:

ret – Boolean as to whether the array contains nans.

Examples

>>> x = ivy.array([1, 2, 3])
>>> y = x.has_nans()
>>> print(y)
False
inplace_decrement(val)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – The input array to be decremented by the defined value.

  • val (Union[Array, NativeArray]) – The value of decrement.

Return type:

Array

Returns:

ret – The array following an in-place decrement.

Examples

With ivy.Array instance methods:

>>> x = ivy.array([5.7, 4.3, 2.5, 1.9])
>>> y = x.inplace_decrement(1)
>>> print(y)
ivy.array([4.7, 3.3, 1.5, 0.9])
>>> x = ivy.asarray([4., 5., 6.])
>>> y = x.inplace_decrement(2.5)
>>> print(y)
ivy.array([1.5, 2.5, 3.5])
inplace_increment(val)[source]#

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

Parameters:
  • self (Array) – The input array to be incremented by the defined value.

  • val (Union[Array, NativeArray]) – The value of increment.

Return type:

Array

Returns:

ret – The array following an in-place increment.

Examples

With ivy.Array instance methods:

>>> x = ivy.array([5.7, 4.3, 2.5, 1.9])
>>> y = x.inplace_increment(1)
>>> print(y)
ivy.array([6.7, 5.3, 3.5, 2.9])
>>> x = ivy.asarray([4., 5., 6.])
>>> y = x.inplace_increment(2.5)
>>> print(y)
ivy.array([6.5, 7.5, 8.5])
inplace_update(val, /, *, ensure_in_backend=False, keep_input_dtype=False)[source]#

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

Parameters:
  • self (Array) – input array to update

  • val (Union[Array, NativeArray]) – The array to update the variable with.

  • ensure_in_backend (bool, default: False) – Whether to ensure that the ivy.NativeArray is also inplace updated. In cases where it should be, backends which do not natively support inplace updates will raise an exception.

  • keep_input_dtype (bool, default: False) – Whether or not to preserve x data type after the update, otherwise val data type will be applied. Defaults to False.

Return type:

Array

Returns:

ret – The array following the in-place update.

Examples

With ivy.Array input and default backend set as numpy:

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.array([0])
>>> x.inplace_update(y)
>>> print(x)
ivy.array([0])

With ivy.Array input and default backend set as numpy:

>>> x = ivy.array([1, 2, 3], dtype=ivy.float32)
>>> y = ivy.array([0, 0, 0], dtype=ivy.int32)
>>> x.inplace_update(y, keep_input_dtype=True)
>>> print(x)
ivy.array([0., 0., 0.])

With ivy.Array input and default backend set as torch:

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.array([0])
>>> x.inplace_update(y)
>>> print(x)
ivy.array([0])

With ivy.Array input and default backend set as jax:

>>> x = ivy.array([4, 5, 6])
>>> y = ivy.array([1])
>>> x.inplace_update(y)
IvyBackendException: jax: inplace_update: JAX does not natively
support inplace updates
is_array(*, exclusive=False)[source]#

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

Parameters:
  • self (Array) – The input to check

  • exclusive (bool, default: False) – Whether to check if the data type is exclusively an array, rather than a variable or traced array.

Return type:

bool

Returns:

ret – Boolean, whether or not x is an array.

Examples

>>> x = ivy.array([0, 1, 2])
>>> print(x.is_array())
True
is_ivy_array(*, exclusive=False)[source]#

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

Parameters:
  • self (Array) – input array

  • exclusive (bool, default: False) – Whether to check if the data type is exclusively an array, rather than a variable or traced array.

Return type:

bool

Returns:

ret – Boolean, whether or not x is an ivy array.

Examples

>>> x = ivy.array([0, 1, 2])
>>> ret = x.is_ivy_array()
>>> print(ret)
True
is_ivy_container()[source]#

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

Parameters:

self (Array) – The input to check

Return type:

bool

Returns:

ret – Boolean, whether or not x is an ivy container.

Examples

>>> x = ivy.array([0, 1, 2])
>>> print(x.is_ivy_container())
False
is_native_array(*, exclusive=False)[source]#

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

Parameters:
  • self (Array) – The input to check

  • exclusive (bool, default: False) – Whether to check if the data type is exclusively an array, rather than a variable or traced array.

Return type:

Array

Returns:

ret – Boolean, whether or not x is a native array.

Examples

>>> x = ivy.array([0, 1, 2])
>>> ret = x.is_native_array()
>>> print(ret)
False
isin(test_elements, /, *, assume_unique=False, invert=False)[source]#

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

Parameters:
  • self (Array) – input array

  • test_elements (Array) – values against which to test for each input element

  • assume_unique (bool, default: False) – If True, assumes both elements and test_elements contain unique elements, which can speed up the calculation. Default value is False.

  • invert (bool, default: False) – If True, inverts the boolean return array, resulting in True values for elements not in test_elements. Default value is False.

Return type:

Array

Returns:

ret – output a boolean array of the same shape as elements that is True for elements in test_elements and False otherwise.

Examples

>>> x = ivy.array([[10, 7, 4], [3, 2, 1]])
>>> y = ivy.array([1, 2, 3])
>>> x.isin(y)
ivy.array([[False, False, False], [ True,  True,  True]])
>>> x = ivy.array([3, 2, 1, 0])
>>> y = ivy.array([1, 2, 3])
>>> x.isin(y, invert=True)
ivy.array([False, False, False,  True])
scatter_flat(updates, /, *, size=None, reduction='sum', out=None)[source]#

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

Parameters:
  • self (Array) – input array containing the indices where the new values will occupy

  • updates (Union[Array, NativeArray]) – Values for the new array to hold.

  • size (Optional[int], default: None) – The size of the result. Default is None, in which case tensor argument out must be provided.

  • reduction (str, default: 'sum') – The reduction method for the scatter, one of ‘sum’, ‘min’, ‘max’ or ‘replace’

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – New array of given shape, with the values scattered at the indices.

Examples

With ivy.Array input: >>> indices = ivy.array([0, 0, 1, 0, 2, 2, 3, 3]) >>> updates = ivy.array([5, 1, 7, 2, 3, 2, 1, 3]) >>> size = 8 >>> out = indices.scatter_flat(updates, size=size) >>> print(out) ivy.array([2, 7, 2, 3, 0, 0, 0, 0])

With ivy.Array input: >>> indices = ivy.array([0, 0, 1, 0, 2, 2, 3, 3]) >>> updates = ivy.array([5, 1, 7, 2, 3, 2, 1, 3]) >>> out = ivy.array([0, 0, 0, 0, 0, 0, 0, 0]) >>> indices.scatter_flat(updates, out=out) >>> print(out) ivy.array([8, 7, 5, 4, 0, 0, 0, 0])

scatter_nd(updates, /, shape=None, *, reduction='sum', out=None)[source]#

Scatter updates into an array according to indices.

Parameters:
  • self (Array) – array of indices

  • updates (Union[Array, NativeArray]) – values to update input tensor with

  • shape (Optional[Array], default: None) – The shape of the result. Default is None, in which case tensor argument must be provided.

  • reduction (str, default: 'sum') – The reduction method for the scatter, one of ‘sum’, ‘min’, ‘max’ or ‘replace’

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Array

Returns:

ret – New array of given shape, with the values scattered at the indices.

Examples

With scatter values into an array

>>> arr = ivy.array([1,2,3,4,5,6,7,8, 9, 10])
>>> indices = ivy.array([[4], [3], [1], [7]])
>>> updates = ivy.array([9, 10, 11, 12])
>>> scatter = indices.scatter_nd(updates, reduction='replace', out=arr)
>>> print(scatter)
ivy.array([ 1, 11,  3, 10,  9,  6,  7, 12,  9, 10])

With scatter values into an empty array

>>> shape = ivy.array([2, 5])
>>> indices = ivy.array([[1,4], [0,3], [1,1], [0,2]])
>>> updates = ivy.array([25, 40, 21, 22])
>>> scatter = indices.scatter_nd(updates, shape=shape)
>>> print(scatter)
ivy.array([[ 0,  0, 22, 40,  0],
            [ 0, 21,  0,  0, 25]])
stable_divide(denominator, /, *, min_denominator=None)[source]#

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

Parameters:
  • self – input array, used as the numerator for division.

  • denominator (Union[Number, Array, NativeArray, Container]) – denominator for division.

  • min_denominator (Optional[Union[Number, Array, NativeArray, Container]], default: None) – the minimum denominator to use, use global ivy._MIN_DENOMINATOR by default.

Return type:

Array

Returns:

ret – a numpy array containing the elements of numerator divided by the corresponding element of denominator

Examples

With ivy.Array instance method:

>>> x = ivy.asarray([4., 5., 6.])
>>> y = x.stable_divide(2)
>>> print(y)
ivy.array([2., 2.5, 3.])
>>> x = ivy.asarray([4, 5, 6])
>>> y = x.stable_divide(4, min_denominator=1)
>>> print(y)
ivy.array([0.8, 1. , 1.2])
>>> x = ivy.asarray([[4., 5., 6.], [7., 8., 9.]])
>>> y = ivy.asarray([[1., 2., 3.], [2., 3., 4.]])
>>> z = x.stable_divide(y)
>>> print(z)
ivy.array([[4.  , 2.5 , 2.  ],
        [3.5 , 2.67, 2.25]])
stable_pow(exponent, /, *, min_base=None)[source]#

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

Parameters:
  • self (Array) – input array, used as the base.

  • exponent (Union[Number, Array, NativeArray]) – The exponent number.

  • min_base (Optional[float], default: None) – The minimum base to use, use global ivy.min_base by default.

Return type:

Array

Returns:

ret – The new item following the numerically stable power.

Examples

With ivy.Array instance method:

>>> x = ivy.asarray([2, 4])
>>> y = x.stable_pow(2)
>>> print(y)
ivy.array([ 4.00004, 16.00008])
>>> x = ivy.asarray([[2., 4.], [6., 8.]])
>>> y = ivy.asarray([2., 4.])
>>> z = x.stable_pow(y)
>>> print(z)
ivy.array([[4.00004000e+00, 2.56002560e+02],
        [3.60001200e+01, 4.09602048e+03]])
supports_inplace_updates()[source]#

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

Parameters:

self (Array) – The input array whose elements’ data type is to be checked.

Return type:

bool

Returns:

ret – Bool value depends on whether the currently active backend framework supports in-place operations with argument’s data type.

Examples

With ivy.Array input and default backend set as numpy:

>>> x = ivy.array([0, 1, 2])
>>> ret = x.supports_inplace_updates()
>>> print(ret)
True

With ivy.Array input and backend set as “tensorflow”:

>>> x = ivy.array([1., 4.2, 2.2])
>>> ret = x.supports_inplace_updates()
>>> print(ret)
False
to_file(fid, sep='', format_='%s')[source]#

ivy.Array instance method variant of to_file. Write array to a file as text or binary. The data is always written in ‘C’ order.

Parameters:
  • self (ivy.Array) – Input array.

  • fid (str, bytes, int) – An open file object, or a string containing a filename.

  • sep (str, optional) – Separator between array items for text output. If ‘’, a binary file is written.

  • format (str, optional) – Format string for text file output.

Return type:

None

Returns:

None

Examples

With ivy.Array instance method:

>>> x = ivy.array([1, 2, 3])
>>> x.to_file('data.txt', sep=',', format_='%d')

Notes

The data produced by this method can be recovered using appropriate methods or functions depending on the data type.

to_list()[source]#

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

Parameters:

self (Array) – input array.

Return type:

List

Returns:

ret – A list representation of the input array x.

Examples

With ivy.Array instance method:

>>> x = ivy.array([0, 1, 2])
>>> y = x.to_list()
>>> print(y)
[0, 1, 2]
to_numpy(*, copy=True)[source]#

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

Parameters:
  • self (Array) – input array.

  • copy (bool, default: True) – whether to copy the array to a new address or not. Default is True.

Return type:

ndarray

Returns:

ret – a numpy array copying all the element of the array self.

Examples

With ivy.Array inputs:

>>> x = ivy.array([-1, 0, 1])
>>> y = x.to_numpy()
>>> print(y)
[-1  0  1]
>>> x = ivy.array([[-1, 0, 1],[-1, 0, 1], [1,0,-1]])
>>> y = x.to_numpy()
>>> print(y)
[[-1  0  1]
[-1  0  1]
[ 1  0 -1]]
to_scalar()[source]#

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

Parameters:

self (Array) – input array.

Return type:

Number

Returns:

ret – a scalar copying the element of the array x.

Examples

With ivy.Array instance method:

>>> x = ivy.array([3])
>>> y = x.to_scalar()
>>> print(y)
3
value_is_nan(*, include_infs=True)[source]#

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

Parameters:
  • self (Array) – input array

  • include_infs (bool, default: True) – Whether to include infs and -infs in the check. Default is True.

Return type:

bool

Returns:

ret – Boolean as to whether the input value is a nan or not.

Examples

With one ivy.Array instance method:

>>> x = ivy.array([92])
>>> y = x.value_is_nan()
>>> print(y)
False
>>> x = ivy.array([float('inf')])
>>> y = x.value_is_nan()
>>> print(y)
True
>>> x = ivy.array([float('nan')])
>>> y = x.value_is_nan()
>>> print(y)
True
>>> x = ivy.array([float('inf')])
>>> y = x.value_is_nan(include_infs=False)
>>> print(y)
False