Experimental#

class ivy.data_classes.array.experimental.activations._ArrayWithActivationsExperimental[source]#
_abc_impl = <_abc._abc_data object>#
celu(*, alpha=1.0, complex_mode='jax', out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • alpha (float, default: 1.0) – the alpha (negative slope) value for CELU formulation.

  • complex_mode (Literal['split', 'magnitude', 'jax'], default: 'jax') – optional specifier for how to handle complex data types. See ivy.func_wrapper.handle_complex_input for more detail.

  • 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 celu activation function applied element-wise.

Examples

>>> x = ivy.array([0.39, -0.85])
>>> y = x.celu()
>>> print(y)
ivy.array([ 0.39, -0.57])
elu(*, alpha=1.0, out=None)[source]#

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

Parameters:
  • self – input array.

  • alpha (float, default: 1.0) – scaler for controlling the slope of the function for x <= 0 Default: 1.0

  • 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 elu activation function applied element-wise.

Examples

>>> x = ivy.array([0.39, -0.85])
>>> y = x.elu()
>>> print(y)
ivy.array([ 0.39, -0.57])
hardshrink(*, lambd=0.5, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • lambd (float, default: 0.5) – the lambd value for the Hardshrink formulation

  • 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 hardshrink activation function applied element-wise.

Examples

>>> x = ivy.array([-1., 0., 1.])
>>> y = x.hardshrink()
>>> print(y)
ivy.array([-1.,  0.,  1.])
>>> x = ivy.array([-1., 0., 1.])
>>> y = x.hardshrink(lambd=1.0)
>>> print(y)
ivy.array([0., 0., 0.])
hardsilu(out=None)[source]#

ivy.Array instance method which acts as a wrapper for ivy.hardsilu.

Parameters:
  • self – input array

  • 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:

an array containing the output of the hardsilu/hardswish function applied to each element in x.

Examples

>>> x = ivy.array([1., 2., 3.])
>>> y = x.hardsilu()
>>> print(y)
ivy.array([0.66666667, 1.66666667, 3.])
hardtanh(*, max_val=1, min_val=-1, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • min_val (float, default: -1) – minimum value of the linear region range. Default: -1.

  • max_val (float, default: 1) – maximum value of the linear region range. Default: 1.

  • 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 hardtanh activation function applied element-wise with custom linear region range.

Examples

>>> x = ivy.array([-1., .2, 1.])
>>> y = x.hardtanh()
>>> print(y)
ivy.array([-1. ,  0.2,  1. ])
logit(*, eps=None, complex_mode='jax', out=None)[source]#

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

Parameters:
  • self – Input array.

  • eps (Optional[float], default: None) – When eps is None the function outputs NaN where x < 0 or x > 1. and inf or -inf where x = 1 or x = 0, respectively. Otherwise if eps is defined, x is clamped to [eps, 1 - eps]

  • complex_mode (Literal['split', 'magnitude', 'jax'], default: 'jax') – optional specifier for how to handle complex data types. See ivy.func_wrapper.handle_complex_input for more detail.

  • out (Optional[Array], default: None) – Optional output array.

Return type:

Array

Returns:

ret – Array containing elementwise logits of x.

Examples

>>> x = ivy.array([1, 0, 0.9])
>>> z = x.logit()
>>> print(z)
ivy.array([       inf,       -inf, 2.19722438])
>>> x = ivy.array([1, 2, -0.9])
>>> z = x.logit(eps=0.2)
>>> print(z)
ivy.array([ 1.38629448,  1.38629448, -1.38629436])
logsigmoid(complex_mode='jax')[source]#

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

Parameters:
  • self (Array) – Input array.

  • complex_mode (Literal['split', 'magnitude', 'jax'], default: 'jax') – optional specifier for how to handle complex data types. See ivy.func_wrapper.handle_complex_input for more detail.

Return type:

Array

Returns:

Array with same shape as input with Log-sigmoid applied to every element.

Examples

>>> x = ivy.array([-1., 2., 4., -10.])
>>> z = x.logsigmoid()
>>> print(z)
ivy.array([ -1.31326175,  -0.126928  ,  -0.01814993, -10.00004578])
>>> x = ivy.array([-2.5, 1., 0, 4.5])
>>> z = x.logsigmoid()
>>> print(z)
ivy.array([-2.57888985, -0.31326169, -0.69314718, -0.01104775])
prelu(slope, /, *, out=None)[source]#

Prelu takes input data (Array) and slope array as input,

and produces one output data (array) where the function f(x) = slope * x for x < 0, f(x) = x for x >= 0., is applied to the data array elementwise. This operator supports unidirectional broadcasting (array slope should be unidirectional broadcastable to input tensor X);

Parameters:
  • self – input array.

  • slope (Union[float, NativeArray, Array]) – Slope Array. The shape of slope can be smaller than first input X; if so, its shape must be unidirectional broadcastable to X.

  • out (Optional[Array], default: None) – Optional output array.

Return type:

Array

Returns:

ret – input array with prelu applied elementwise.

relu6(*, complex_mode='jax', out=None)[source]#

Apply the rectified linear unit 6 function element-wise.

Parameters:
  • self – input array

  • complex_mode (Literal['split', 'magnitude', 'jax'], default: 'jax') – optional specifier for how to handle complex data types. See ivy.func_wrapper.handle_complex_input for more detail.

  • 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 containing the rectified linear unit 6 activation of each element in input.

Examples

With ivy.Array input:

>>> x = ivy.array([-1.,  0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.])
>>> y = ivy.relu6(x)
>>> print(y)
ivy.array([0., 0., 1., 2., 3., 4., 5., 6., 6.])
>>> x = ivy.array([-1.,  0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.])
>>> y = ivy.zeros(9)
>>> ivy.relu6(x, out = y)
>>> print(y)
ivy.array([0., 0., 1., 2., 3., 4., 5., 6., 6.])
scaled_tanh(*, alpha=1.7159, beta=0.67, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • alpha (float, default: 1.7159) – The scaling parameter for the output. Determines the amplitude of the tanh function. Default: 1.7159

  • beta (float, default: 0.67) – The scaling parameter for the input. Determines the slope of the tanh function. Default: 0.67

  • 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 after applying the scaled_tanh activation.

Examples

>>> x = ivy.array([-3., 2., 3.])
>>> x.scaled_tanh()
ivy.array([-1.65537548,  1.49570239,  1.65537548])
>>> x = ivy.array([2., 2., 2.])
>>> x.scaled_tanh(alpha=9, beta=0.1)
ivy.array([1.77637792, 1.77637792, 1.77637792])
>>> x = ivy.array([2., 2., 2.])
>>> x.scaled_tanh(alpha=0.1, beta=9)
ivy.array([0.1, 0.1, 0.1])
selu(*, out=None)[source]#

Apply the scaled exponential linear unit function element-wise.

Parameters:
  • self – input array

  • 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 containing the scaled exponential linear unit activation of each element in input.

Examples

With ivy.Array input:

>>> x = ivy.array([-1.,  0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.])
>>> y = x.selu()
>>> print(y)
ivy.array([-1.11133075,  0.,  1.05070102,  2.10140204,  3.15210295,
            4.20280409,  5.25350523,  6.30420589,  7.35490704])
>>> x = ivy.array([-1.,  0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.])
>>> y = ivy.zeros(9)
>>> x.selu(out = y)
>>> print(y)
ivy.array([-1.11133075,  0.,  1.05070102,  2.10140204,  3.15210295,
            4.20280409,  5.25350523,  6.30420589,  7.35490704])
silu(*, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • 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

Examples

>>> x = ivy.array([-1., 0., 1.])
>>> y = x.silu()
>>> print(y)
ivy.array([-0.26894143,  0.        ,  0.73105854])
softshrink(*, lambd=0.5, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • lambd (float, default: 0.5) – the value of the lower bound of the linear region range.

  • 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 softshrink activation function applied element-wise.

Examples

>>> x = ivy.array([-1., 0., 1.])
>>> y = x.softshrink()
>>> print(y)
ivy.array([-0.5,  0. ,  0.5])
>>> x = ivy.array([-1., 0., 1.])
>>> y = x.softshrink(lambd=1.0)
>>> print(y)
ivy.array([0., 0., 0.])
tanhshrink(*, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • 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

Examples

>>> x = ivy.array([-1., 0., 1.])
>>> y = x.tanhshrink()
>>> print(y)
ivy.array([-0.23840582,  0.        ,  0.23840582])
threshold(*, threshold, value, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • threshold (Union[int, float]) – threshold value for thresholding operation.

  • value (Union[int, float]) – value to replace with if thresholding condition is not met.

  • 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 thresholding function applied element-wise.

Examples

>>> x = ivy.array([-1., 0., 1.])
>>> y = x.hreshold(threshold=0.5, value=0.0)
>>> print(y)
ivy.array([0.5, 0.5 , 1. ])
thresholded_relu(*, threshold=0, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • threshold (Union[int, float], default: 0) – threshold value above which the activation is linear. Default: 0.

  • 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 relu activation function applied element-wise with custom threshold.

Examples

>>> x = ivy.array([-1., .2, 1.])
>>> y = x.thresholded_relu(threshold=0.5)
>>> print(y)
ivy.array([0., 0., 1.])
class ivy.data_classes.array.experimental.conversions._ArrayWithConversionsExperimental[source]#
_abc_impl = <_abc._abc_data object>#
class ivy.data_classes.array.experimental.creation._ArrayWithCreationExperimental[source]#
_abc_impl = <_abc._abc_data object>#
blackman_window(*, periodic=True, dtype=None, device=None, out=None)[source]#

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

Parameters:
  • self (Array) – int.

  • periodic (bool, default: True) – If True, returns a window to be used as periodic function. If False, return a symmetric window. Default: True.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – output array data type. If dtype is None, the output array data type must be inferred from self. Default: None.

  • device (Optional[Union[Device, NativeDevice]], default: None) – device on which to place the created array. If device is None, the output array device must be inferred from self. Default: None.

  • 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 – The array containing the window.

Examples

>>> ivy.blackman_window(4, periodic = True)
ivy.array([-1.38777878e-17,  3.40000000e-01,  1.00000000e+00,  3.40000000e-01])
>>> ivy.blackman_window(7, periodic = False)
ivy.array([-1.38777878e-17,  1.30000000e-01,  6.30000000e-01,  1.00000000e+00,
6.30000000e-01,  1.30000000e-01, -1.38777878e-17])
eye_like(*, k=0, dtype=None, device=None, out=None)[source]#

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

Parameters:
  • self (Array) – input array from which to derive the output array shape.

  • k (int, default: 0) – index of the diagonal. A positive value refers to an upper diagonal, a negative value to a lower diagonal, and 0 to the main diagonal. Default: 0.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – output array data type. If dtype is None, the output array data type must be inferred from self. Default: None.

  • device (Optional[Union[Device, NativeDevice]], default: None) – device on which to place the created array. If device is None, the output array device must be inferred from self. Default: None.

  • 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 having the same shape as self and filled with ones in diagonal k and zeros elsewhere.

Examples

>>> x = ivy.array([[2, 3, 8],[1, 2, 1]])
>>> y = x.eye_like()
>>> print(y)
ivy.array([[1., 0., 0.],
            0., 1., 0.]])
static mel_weight_matrix(num_mel_bins, dft_length, sample_rate, lower_edge_hertz=0.0, upper_edge_hertz=3000.0)[source]#

Generate a MelWeightMatrix that can be used to re-weight a Tensor containing a linearly sampled frequency spectra (from DFT or STFT) into num_mel_bins frequency information based on the [lower_edge_hertz, upper_edge_hertz]

range on the mel scale. This function defines the mel scale in terms of a frequency in hertz according to the following formula: mel(f) = 2595 * log10(1 + f/700)

Parameters:
  • num_mel_bins (Union[int, Array]) – The number of bands in the mel spectrum.

  • dft_length (Union[int, Array]) – The size of the original DFT obtained from (n_fft / 2 + 1).

  • sample_rate (Union[int, Array]) – Samples per second of the input signal.

  • lower_edge_hertz (Optional[Union[float, Array]], default: 0.0) – Lower bound on the frequencies to be included in the mel spectrum.

  • upper_edge_hertz (Optional[Union[float, Array]], default: 3000.0) – The desired top edge of the highest frequency band.

Returns:

ret – MelWeightMatrix of shape: [frames, num_mel_bins].

Examples

>>> x = ivy.array([[1, 2, 3],
>>>                [1, 1, 1],
>>>                [5,6,7  ]])
>>> x.mel_weight_matrix(3, 3, 8000)
ivy.array([[0.        ,0.        , 0.],
          [0.        ,0. , 0.75694758],
          [0.        ,0. , 0.       ]])
trilu(*, k=0, upper=True, out=None)[source]#

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

Parameters:
  • self (Array) – input array having shape (…, M, N) and whose innermost two dimensions form MxN matrices. *,

  • k (int, default: 0) – diagonal below or above which to zero elements. If k = 0, the diagonal is the main diagonal. If k < 0, the diagonal is below the main diagonal. If k > 0, the diagonal is above the main diagonal. Default: 0.

  • upper (bool, default: True) – indicates whether upper or lower part of matrix is retained. Default: True.

  • 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 containing the upper triangular part(s). The returned array must have the same shape and data type as self. All elements below the specified diagonal k must be zeroed. The returned array should be allocated on the same device as self.

unsorted_segment_mean(segment_ids, num_segments)[source]#

Compute the mean of values in the array ‘self’ based on segment identifiers.

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

  • segment_ids (ivy.Array) – Must be in the same size with the first dimension of self. Has to be of integer data type. The index-th element of segment_ids array is the segment identifier for the index-th element of self.

  • num_segments (Union[int, ivy.Array]) – An integer or array representing the total number of distinct segment IDs.

Return type:

Array

Returns:

ret (ivy.Array) – The output array, representing the result of a segmented mean operation. For each segment, it computes the mean of values in self where segment_ids equals to segment ID.

Examples

>>> data = ivy.array([1.0, 2.0, 3.0, 4.0])
>>> segment_ids = ivy.array([0, 0, 0, 0])
>>> num_segments = 1
>>> result = ivy.unsorted_segment_mean(data, segment_ids, num_segments)
>>> result
ivy.array([2.5])
>>> data = ivy.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
>>> segment_ids = ivy.array([0, 0, 1, 1, 2, 2])
>>> num_segments = 3
>>> result = ivy.unsorted_segment_mean(data, segment_ids, num_segments)
>>> result
ivy.array([[1.5, 3.5, 5.5],[1.5, 3.5, 5.5],[1.5, 3.5, 5.5]])
unsorted_segment_min(segment_ids, num_segments)[source]#

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

Note

If the given segment ID i is negative, then the corresponding value is dropped, and will not be included in the result.

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

  • segment_ids (Array) – Must be in the same size with the first dimension of self. Has to be of integer data type. The index-th element of segment_ids array is the segment identifier for the index-th element of self.

  • num_segments (Union[int, Array]) – An integer or array representing the total number of distinct segment IDs.

Return type:

Array

Returns:

ret – The output array, representing the result of a segmented min operation. For each segment, it computes the min value in self where segment_ids equals to segment ID.

unsorted_segment_sum(segment_ids, num_segments)[source]#

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

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

  • segment_ids (Array) – Must be in the same size with the first dimension of self. Has to be of integer data type. The index-th element of segment_ids array is the segment identifier for the index-th element of self.

  • num_segments (Union[int, Array]) – An integer or array representing the total number of distinct segment IDs.

Return type:

Array

Returns:

ret – The output array, representing the result of a segmented sum operation. For each segment, it computes the sum of values in self where segment_ids equals to segment ID.

ivy.data_classes.array.experimental.creation.polyval(coeffs=<class 'ivy.Array'>, x=typing.Union[ivy.Array, ivy.NativeArray, int, float], /, *, dtype=None, device=None)[source]#

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

Evaluate and return a polynomial at specific given values.

Parameters:
  • coeffs (default: <class 'ivy.Array'>) – Input array containing polynomial coefficients (including zero) from highest degree to constant term.

  • x (default: typing.Union[ivy.Array, ivy.NativeArray, int, float]) – The value of the indeterminate variable at which to evaluate the polynomial.

Return type:

Array

Returns:

ret – Simplified result of substituting x in the coefficients - final value of polynomial.

Examples

>>> x = ivy.array([[0, 0, 0])
>>> x.polyval([3, 0, 1], 5)
ivy.array(76)
class ivy.data_classes.array.experimental.data_type._ArrayWithData_typeExperimental[source]#
_abc_impl = <_abc._abc_data object>#
class ivy.data_classes.array.experimental.device._ArrayWithDeviceExperimental[source]#
_abc_impl = <_abc._abc_data object>#
class ivy.data_classes.array.experimental.elementwise._ArrayWithElementWiseExperimental[source]#
_abc_impl = <_abc._abc_data object>#
allclose(x2, /, *, rtol=1e-05, atol=1e-08, equal_nan=False, out=None)[source]#

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

Parameters:
  • self (Array) – First input array.

  • x2 (Array) – Second input array.

  • rtol (float, default: 1e-05) – The relative tolerance parameter.

  • atol (float, default: 1e-08) – The absolute tolerance parameter.

  • equal_nan (bool, default: False) – Whether to compare NaN’s as equal. If True, NaN’s in a will be considered equal to NaN’s in b in the output array.

  • out (Optional[Container], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

bool

Returns:

ret – Returns True if the two arrays are equal within the given tolerance; False otherwise.

Examples

>>> x1 = ivy.array([1e10, 1e-7])
>>> x2 = ivy.array([1.00001e10, 1e-8])
>>> y = x1.allclose(x2)
>>> print(y)
ivy.array(False)
>>> x1 = ivy.array([1.0, ivy.nan])
>>> x2 = ivy.array([1.0, ivy.nan])
>>> y = x1.allclose(x2, equal_nan=True)
>>> print(y)
ivy.array(True)
>>> x1 = ivy.array([1e-10, 1e-10])
>>> x2 = ivy.array([1.00001e-10, 1e-10])
>>> y = x1.allclose(x2, rtol=0.005, atol=0.0)
>>> print(y)
ivy.array(True)
amax(*, axis=None, keepdims=False, out=None)[source]#

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

Parameters:
  • self (Array) – input array. Should have a real-valued data type.

  • axis (Optional[Union[int, Sequence[int]]], default: None) – axis or axes along which maximum values must be computed. By default, the maximum value must be computed over the entire array. If a tuple of integers, maximum values must be computed over multiple axes. Default: None.

  • keepdims (bool, default: False) – optional boolean, if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see `broadcasting<https://data-apis.org/array-api/latest/ API_specification/broadcasting.html#broadcasting>`_). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: False.

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

Return type:

Array

Returns:

ret – if the maximum value was computed over the entire array, a zero-dimensional array containing the maximum value; otherwise, a non-zero-dimensional array containing the maximum values. The returned array must have the same data type as x.

Examples

>>> x = ivy.array([3., 4., 5.])
>>> y = x.amax()
>>> print(y)
ivy.array(5.)
>>> x = ivy.array([[-1, 0, 1], [2, 3, 4]])
>>> y = x.amax(axis=1)
>>> print(y)
ivy.array([1,  4])
>>> x = ivy.array([0.1, 1.1, 2.1])
>>> y = ivy.array(0.)
>>> x.amax(out=y)
>>> print(y)
ivy.array(2.1)
amin(*, axis=None, keepdims=False, out=None)[source]#

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

Parameters:
  • self (Array) – input array. Should have a real-valued data type.

  • axis (Optional[Union[int, Sequence[int]]], default: None) – axis or axes along which minimum values must be computed. By default, the minimum value must be computed over the entire array. If a tuple of integers, minimum values must be computed over multiple axes. Default: None.

  • keepdims (bool, default: False) – optional boolean, if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see `broadcasting<https://data-apis.org/array-api/latest/ API_specification/broadcasting.html#broadcasting>`_). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: False.

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

Return type:

Array

Returns:

ret – if the minimum value was computed over the entire array, a zero-dimensional array containing the minimum value; otherwise, a non-zero-dimensional array containing the minimum values. The returned array must have the same data type as x.

Examples

>>> x = ivy.array([3., 4., 5.])
>>> y = x.amin()
>>> print(y)
ivy.array(3.)
>>> x = ivy.array([[-1, 0, 1], [2, 3, 4]])
>>> y = x.amin(axis=1)
>>> print(y)
ivy.array([-1,  2])
>>> x = ivy.array([0.1, 1.1, 2.1])
>>> y = ivy.array(0.)
>>> x.amin(out=y)
>>> print(y)
ivy.array(0.1)
binarizer(*, threshold=0, out=None)[source]#

Map the values of the input tensor to either 0 or 1, element-wise, based on the outcome of a comparison against a threshold value.

Parameters:
  • self (Array) – Data to be binarized

  • threshold (float, default: 0) – Values greater than this are mapped to 1, others to 0.

  • 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 – Binarized output data

conj(*, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • 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 containing the complex conjugates of values in the input array, with the same dtype as the input array.

Examples

>>> x = ivy.array([4+3j, 6+2j, 1-6j])
>>> x.conj()
ivy.array([4-3j, 6-2j, 1+6j])
copysign(x2, /, *, out=None)[source]#

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

Parameters:
  • x1 – Array or scalar to change the sign of

  • x2 (Union[Array, NativeArray, Number]) – Array or scalar from which the new signs are applied Unsigned zeroes are considered positive.

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

Return type:

Array

Returns:

ret – x1 with the signs of x2. This is a scalar if both x1 and x2 are scalars.

Examples

>>> x1 = ivy.array([0, 1, 2, 3])
>>> x2 = ivy.array([-1, 1, -2, 2])
>>> x1.copysign(x2)
ivy.array([-0.,  1., -2.,  3.])
>>> x2.copysign(-1)
ivy.array([-1., -1., -2., -2.])
count_nonzero(*, axis=None, keepdims=False, dtype=None, out=None)[source]#

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

Parameters:
  • self (Array) – input array for which to count non-zeros.

  • axis (Optional[Union[int, Tuple[int, ...]]], default: None) – optional axis or tuple of axes along which to count non-zeros. Default is None, meaning that non-zeros will be counted along a flattened version of the input array.

  • keepdims (bool, default: False) – optional, if this is set to True, the axes that are counted are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – optional output dtype. Default is of type integer.

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

Return type:

Array

Returns:

ret – Number of non-zero values in the array along a given axis. Otherwise, the total number of non-zero values in the array is returned.

Examples

>>> x = ivy.array([1, 2, 3])
>>> x.count_nonzero()
ivy.array(3)
>>> x = ivy.array([[[0,1],[2,3]],[[4,5],[6,7]]])
>>> x.count_nonzero(axis=0)
ivy.array([[1, 2],
       [2, 2]])
>>> x = ivy.array([[[0,1],[2,3]],[[4,5],[6,7]]])
>>> x.count_nonzero(axis=(0,1), keepdims=True)
ivy.array([[[3, 4]]])
diff(*, n=1, axis=-1, prepend=None, append=None, out=None)[source]#

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

Parameters:
  • self (Array) – array-like input.

  • n (int, default: 1) – The number of times values are differenced. If zero, the input is returned as-is.

  • axis (int, default: -1) – The axis along which the difference is taken, default is the last axis.

  • prepend (Optional[Union[Array, NativeArray, int, list, tuple]], default: None) – Values to prepend/append to x along given axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match x except along axis.

  • append (Optional[Union[Array, NativeArray, int, list, tuple]], default: None) – Values to prepend/append to x along given axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match x except along axis.

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

Return type:

Array

Returns:

ret – Returns the n-th discrete difference along the given axis.

Examples

>>> x = ivy.array([1, 2, 4, 7, 0])
>>> x.diff()
ivy.array([ 1,  2,  3, -7])
digamma(*, out=None)[source]#

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

Note

The Ivy version only accepts real-valued inputs.

Parameters:
  • self (Array) – Input array.

  • out (Optional[Array], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – Array with values computed from digamma function from input arrays’ values, element-wise.

Examples

>>> x = ivy.array([.9, 3, 3.2])
>>> y = ivy.digamma(x)
ivy.array([-0.7549271   0.92278427  0.9988394])
erfc(*, out=None)[source]#

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

Parameters:
  • self (Array) – Input array with real or complex valued argument.

  • out (Optional[Array], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – Values of the complementary error function.

Examples

>>> x = ivy.array([0, -1., 10.])
>>> x.erfc()
ivy.array([1.00000000e+00, 1.84270084e+00, 2.80259693e-45])
erfinv(*, out=None)[source]#

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

Parameters:
  • self (Array) – Input array with real or complex valued argument.

  • out (Optional[Array], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – Values of the inverse error function.

Examples

>>> x = ivy.array([0, -1., 10.])
>>> x.erfinv()
ivy.array([1.00000000e+00, 1.84270084e+00, 2.80259693e-45])
fix(*, out=None)[source]#

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

Parameters:
  • self (Array) – Array input.

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

Return type:

Array

Returns:

ret – Array of floats with elements corresponding to input elements rounded to nearest integer towards zero, element-wise.

Examples

>>> x = ivy.array([2.1, 2.9, -2.1])
>>> x.fix()
ivy.array([ 2.,  2., -2.])
float_power(x2, /, *, out=None)[source]#

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

Parameters:
  • self (Union[Array, float, list, tuple]) – Array-like with elements to raise in power.

  • x2 (Union[Array, float, list, tuple]) – Array-like of exponents. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).

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

Return type:

Array

Returns:

ret – The bases in x1 raised to the exponents in x2. This is a scalar if both x1 and x2 are scalars

Examples

>>> x1 = ivy.array([1, 2, 3, 4, 5])
>>> x1.float_power(3)
ivy.array([1.,    8.,   27.,   64.,  125.])
>>> x1 = ivy.array([1, 2, 3, 4, 5])
>>> x2 = ivy.array([2, 3, 3, 2, 1])
>>> x1.float_power(x2)
ivy.array([1.,   8.,  27.,  16.,   5.])
fmax(x2, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – First input array.

  • x2 (Array) – Second input array

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

Return type:

Array

Returns:

ret – Array with element-wise maximums.

Examples

>>> x1 = ivy.array([2, 3, 4])
>>> x2 = ivy.array([1, 5, 2])
>>> ivy.fmax(x1, x2)
ivy.array([ 2.,  5.,  4.])
>>> x1 = ivy.array([ivy.nan, 0, ivy.nan])
>>> x2 = ivy.array([0, ivy.nan, ivy.nan])
>>> x1.fmax(x2)
ivy.array([ 0,  0,  nan])
fmod(x2, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – First input array.

  • x2 (Array) – Second input array

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

Return type:

Array

Returns:

ret – Array with element-wise remainder of divisions.

Examples

>>> x1 = ivy.array([2, 3, 4])
>>> x2 = ivy.array([1, 5, 2])
>>> x1.fmod(x2)
ivy.array([ 0,  3,  0])
>>> x1 = ivy.array([ivy.nan, 0, ivy.nan])
>>> x2 = ivy.array([0, ivy.nan, ivy.nan])
>>> x1.fmod(x2)
ivy.array([ nan,  nan,  nan])
frexp(*, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • out (Optional[Tuple[Array, Array]], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – The next representable values of x1 in the direction of x2.

Examples

>>> x = ivy.array([1.0, 2.0, 3.0])
>>> x.frexp()
ivy.array([[0.5, 0.5, 0.75], [1, 2, 2]])
gradient(*, spacing=1, edge_order=1, axis=None)[source]#

Calculate gradient of x with respect to (w.r.t.) spacing.

Parameters:
  • self (Union[Array, NativeArray]) – input array representing outcomes of the function

  • spacing (Union[int, list, tuple], default: 1) – if not given, indices of x will be used if scalar indices of x will be scaled with this value if array gradient of x w.r.t. spacing

  • edge_order (int, default: 1) – 1 or 2, for ‘first order’ and ‘second order’ estimation of boundary values of gradient respectively. Note: jax supports edge_order=1 case only

  • axis (Optional[Union[int, list, tuple]], default: None) – dimension(s) to approximate the gradient over by default partial gradient is computed in every dimension

Return type:

Union[Array, List[Array]]

Returns:

ret – Array with values computed from gradient function from inputs

Examples

>>> spacing = (ivy.array([-2., -1., 1., 4.]),)
>>> x = ivy.array([4., 1., 1., 16.], )
>>> ivy.gradient(x, spacing=spacing)
ivy.array([-3., -2.,  2.,  5.])
>>> x = ivy.array([[1, 2, 4, 8], [10, 20, 40, 80]])
>>> ivy.gradient(x)
[ivy.array([[ 9., 18., 36., 72.],
   [ 9., 18., 36., 72.]]), ivy.array([[ 1. ,  1.5,  3. ,  4. ],
   [10. , 15. , 30. , 40. ]])]
>>> x = ivy.array([[1, 2, 4, 8], [10, 20, 40, 80]])
>>> ivy.gradient(x, spacing=2.0)
[ivy.array([[ 4.5,  9. , 18. , 36. ],
   [ 4.5,  9. , 18. , 36. ]]), ivy.array([[ 0.5 ,  0.75,  1.5 ,  2.  ],
   [ 5.  ,  7.5 , 15.  , 20.  ]])]
>>> x = ivy.array([[1, 2, 4, 8], [10, 20, 40, 80]])
>>> ivy.gradient(x, axis=1)
ivy.array([[ 1. ,  1.5,  3. ,  4. ],
   [10. , 15. , 30. , 40. ]])
>>> x = ivy.array([[1, 2, 4, 8], [10, 20, 40, 80]])
>>> ivy.gradient(x, spacing=[3., 2.])
[ivy.array([[ 3.,  6., 12., 24.],
   [ 3.,  6., 12., 24.]]), ivy.array([[ 0.5 ,  0.75,  1.5 ,  2.  ],
   [ 5.  ,  7.5 , 15.  , 20.  ]])]
>>> spacing = (ivy.array([0, 2]), ivy.array([0, 3, 6, 9]))
>>> ivy.gradient(x, spacing=spacing)
[ivy.array([[ 4.5,  9. , 18. , 36. ],
   [ 4.5,  9. , 18. , 36. ]]), ivy.array([[ 0.33333333,  0.5,  1., 1.33333333],
   [ 3.33333333,  5.        , 10.        , 13.33333333]])]
hypot(x2, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – First input array

  • x2 (Array) – Second input array

  • 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 containing the hypotenuse computed from each element of the input arrays.

Examples

>>> x = ivy.array([3.0, 4.0, 5.0])
>>> y = ivy.array([4.0, 5.0, 6.0])
>>> x.hypot(y)
ivy.array([5.0, 6.4031, 7.8102])
isclose(b, /, *, rtol=1e-05, atol=1e-08, equal_nan=False, out=None)[source]#

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

Parameters:
  • self (Array) – First input array.

  • b (Array) – Second input array.

  • rtol (float, default: 1e-05) – The relative tolerance parameter.

  • atol (float, default: 1e-08) – The absolute tolerance parameter.

  • equal_nan (bool, default: False) – Whether to compare NaN’s as equal. If True, NaN’s in a will be considered equal to NaN’s in b in the output array.

  • out (Optional[Array], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – A new array holding the result is returned unless out is specified, in which it is returned.

Examples

>>> a = ivy.array([[ 2.1,  3.4,  ivy.nan], [ivy.nan, 2.4, 2.1]])
>>> b = ivy.array([[ 2.1,  3.4,  ivy.nan], [ivy.nan, 2.4, 2.1]])
>>> a.isclose(b)
ivy.array([[True, True, False],
       [False, True, True]])
>>> a.isclose(b, equal_nan=True)
ivy.array([[True, True, True],
       [True, True, True]])
>>> a=ivy.array([1.0, 2.0])
>>> b=ivy.array([1.0, 2.001])
>>> a.isclose(b, atol=0.0)
ivy.array([True, False])
>>> a.isclose(b, rtol=0.01, atol=0.0)
ivy.array([True, True])
ldexp(x2, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • x2 (Array) – The array of exponents.

  • out (Optional[Array], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – The next representable values of x1 in the direction of x2.

Examples

>>> x = ivy.array([1.0, 2.0, 3.0])
>>> y = ivy.array([3.0, 2.0, 1.0])
>>> x.ldexp(y)
ivy.array([8.0, 8.0, 6.0])
lerp(end, weight, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – Array of starting points

  • end (Array) – Array of ending points

  • weight (Union[Array, float]) – Weight for the interpolation formula , array or scalar.

  • out (Optional[Array], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – The linear interpolation between array self and array end based on scalar or array weight self + ((end - self) * weight)

Examples

>>> x = ivy.array([1.0, 2.0, 3.0, 4.0])
>>> end = ivy.array([10.0, 10.0, 10.0, 10.0])
>>> weight = 0.5
>>> x.lerp(end, weight)
ivy.array([5.5, 6. , 6.5, 7. ])
lgamma(*, out=None)[source]#

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

Parameters:
  • self (Array) – input array. Should have a real-valued floating-point data type.

  • 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 containing the evaluated result for each element in self. The returned array must have a real-valued floating-point data type determined by type-promotion.

Examples

>>> x = ivy.array([1., 2., 3.])
>>> y = x.lgamma()
>>> print(y)
ivy.array([0., 0., 0.69314718])
>>> x = ivy.array([4.5, -4, -5.6])
>>> x.lgamma(out = x)
>>> print(x)
ivy.array([2.45373654, inf, -4.6477685 ])
modf(*, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • out (Optional[Tuple[Array, Array]], default: None) – Alternate output arrays in which to place the result. The default is None.

Return type:

Tuple[Array, Array]

Returns:

ret – The fractional and integral parts of the input array.

Examples

>>> x = ivy.array([1.5, 2.7, 3.9])
>>> x.modf()
(ivy.array([0.5, 0.7, 0.9]), ivy.array([1, 2, 3]))
nansum(*, axis=None, dtype=None, keepdims=False, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • axis (Optional[Union[tuple, int]], default: None) – Axis or axes along which the sum is computed. The default is to compute the sum of the flattened array.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – The type of the returned array and of the accumulator in which the elements are summed. By default, the dtype of input is used.

  • keepdims (bool, default: False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one.

  • out (Optional[Container], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – A new array holding the result is returned unless out is specified, in which it is returned.

Examples

>>> a = ivy.array([[ 2.1,  3.4,  ivy.nan], [ivy.nan, 2.4, 2.1]])
>>> ivy.nansum(a)
10.0
>>> ivy.nansum(a, axis=0)
ivy.array([2.1, 5.8, 2.1])
>>> ivy.nansum(a, axis=1)
ivy.array([5.5, 4.5])
nextafter(x2, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – First input array.

  • x2 (Array) – Second input array.

  • out (Optional[Array], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – The next representable values of x1 in the direction of x2.

Examples

>>> x1 = ivy.array([1.0e-50, 2.0e+50])
>>> x2 = ivy.array([2.0, 1.0])
>>> x1.nextafter(x2)
ivy.array([1.4013e-45., 3.4028e+38])
signbit(*, out=None)[source]#

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

Parameters:
  • self (Union[Array, float, int, list, tuple]) – Array-like input.

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

Return type:

Array

Returns:

ret – Element-wise signbit of x.

Examples

>>> x = ivy.array([1, -2, 3])
>>> x.signbit()
ivy.array([False, True, False])
sinc(*, out=None)[source]#

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

Parameters:
  • self (Array) – input array whose elements are each expressed in radians. Should have a floating-point data type.

  • 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 containing the sinc of each element in self. The returned array must have a floating-point data type determined by type-promotion.

Examples

>>> x = ivy.array([0.5, 1.5, 2.5, 3.5])
>>> y = x.sinc()
>>> print(y)
ivy.array([0.637,-0.212,0.127,-0.0909])
sparsify_tensor(card, /, *, out=None)[source]#

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

Parameters:
  • self (array) – The tensor to sparsify.

  • card (int) – The number of values to keep.

  • out (array, optional) – Optional output array, for writing the result to.

Return type:

Array

Returns:

ret (array) – The sparsified tensor.

Examples

>>> x = ivy.arange(100)
>>> x = ivy.reshape(x, (10, 10))
>>> x.sparsify_tensor(10)
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,  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,  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,  0,  0,  0,  0,  0,  0,  0,  0,  0],
[90, 91, 92, 93, 94, 95, 96, 97, 98, 99]])
xlogy(y, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – First input array.

  • y (Array) – Second input array.

  • out (Optional[Array], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – The next representable values of x1 in the direction of x2.

Examples

>>> x = ivy.zeros(3)
>>> y = ivy.array([-1.0, 0.0, 1.0])
>>> x.xlogy(y)
ivy.array([0.0, 0.0, 0.0])
>>> x = ivy.array([1.0, 2.0, 3.0])
>>> y = ivy.array([3.0, 2.0, 1.0])
>>> x.xlogy(y)
ivy.array([1.0986, 1.3863, 0.0000])
zeta(q, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – First input array.

  • q (Array) – Second input array.

  • out (Optional[Array], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – Array with values computed from zeta function from input arrays’ values.

Examples

>>> x = ivy.array([5.0, 3.0])
>>> q = ivy.array([2.0])
>>> x.zeta(q)
ivy.array([0.0369, 0.2021])
class ivy.data_classes.array.experimental.general._ArrayWithGeneralExperimental[source]#
_abc_impl = <_abc._abc_data object>#
reduce(init_value, computation, /, *, axes=0, keepdims=False)[source]#

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

Parameters:
  • self (Array) – The array to act on.

  • init_value (Union[int, float]) – The value with which to start the reduction.

  • computation (Callable) – The reduction function.

  • axes (Union[int, Sequence[int]], default: 0) – The dimensions along which the reduction is performed.

  • keepdims (bool, default: False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one.

Return type:

Array

Returns:

ret – The reduced array.

Examples

>>> x = ivy.array([[1, 2, 3], [4, 5, 6]])
>>> x.reduce(0, ivy.add, 0)
ivy.array([6, 15])
class ivy.data_classes.array.experimental.gradients._ArrayWithGradientsExperimental[source]#
_abc_impl = <_abc._abc_data object>#
class ivy.data_classes.array.experimental.image._ArrayWithImageExperimental[source]#
_abc_impl = <_abc._abc_data object>#
class ivy.data_classes.array.experimental.layers._ArrayWithLayersExperimental[source]#
_abc_impl = <_abc._abc_data object>#
adaptive_avg_pool1d(output_size)[source]#

Apply a 1D adaptive average pooling over an input signal composed of several input planes.

Parameters:
  • self (Array) – Input array. Must have shape (N, C, L_in) or (C, L_in) where N is the batch dimension, C is the feature dimension, and L_in is the spatial dimension.

  • output_size (int) – Spatial output size.

Return type:

Array

Returns:

The result of the pooling operation. Will have shape (N, C, L_out) or (C, L_out), where L_out = output_size

adaptive_avg_pool2d(output_size, /, *, data_format='NHWC')[source]#

Apply a 2D adaptive average pooling over an input signal composed of several input planes.

Parameters:
  • self (Array) – A 3D or 4D input array. Should have a floating-point data type.

  • output_size (Union[Sequence[int], int]) – Spatial output size.

  • data_format (str, default: 'NHWC') – “NHWC” or “NCHW”. Defaults to “NHWC”.

Return type:

Array

Returns:

The result of the pooling operation. Will have shape (N, C, S_0, S_1) or (C, S_0, S_1), where S = output_size

adaptive_max_pool2d(output_size)[source]#

Apply a 2D adaptive maximum pooling over an input signal composed of several input planes.

Parameters:
  • self (Array) – Input array. Must have shape (N, C, H_in, W_in) or (C, H_in, W_in) where N is the batch dimension, C is the feature dimension, and H_in and W_in are the 2 spatial dimensions.

  • output_size (Union[Sequence[int], int]) – Spatial output size.

Return type:

Array

Returns:

The result of the pooling operation. Will have shape (N, C, S_0, S_1) or (C, S_0, S_1), where S = output_size

adaptive_max_pool3d(output_size)[source]#
Return type:

Array

avg_pool1d(kernel, strides, padding, /, *, data_format='NWC', count_include_pad=False, ceil_mode=False, out=None)[source]#

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

Parameters:
  • self (Array) – Input image [batch_size,w,d_in].

  • kernel (Union[int, Tuple[int]]) – The size of the window for each dimension of the input tensor.

  • strides (Union[int, Tuple[int]]) – The stride of the sliding window for each dimension of input.

  • padding (str) – “SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (str, default: 'NWC') – “NWC” or “NCW”. Defaults to “NWC”.

  • count_include_pad (bool, default: False) – Whether to include padding in the averaging calculation.

  • ceil_mode (bool, default: False) – Whether to use ceil or floor for creating the output shape.

  • 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 – The result of the max pooling operation.

Examples

>>> x = ivy.arange(0, 24.).reshape((2, 3, 4))
>>> print(x.avg_pool1d(2, 2, 'SAME'))
ivy.array([[[ 2.,  3.,  4.,  5.],
        [ 8.,  9., 10., 11.]],
       [[14., 15., 16., 17.],
        [20., 21., 22., 23.]]])
>>> x = ivy.arange(0, 24.).reshape((2, 3, 4))
>>> print(x.avg_pool1d(2, 2, 'VALID'))
ivy.array([[[ 2.,  3.,  4.,  5.]],
       [[14., 15., 16., 17.]]])
avg_pool2d(kernel, strides, padding, /, *, data_format='NHWC', count_include_pad=False, ceil_mode=False, divisor_override=None, out=None)[source]#

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

Parameters:
  • x – Input image [batch_size,h,w,d_in].

  • kernel (Union[int, Tuple[int], Tuple[int, int]]) – The size of the window for each dimension of the input tensor.

  • strides (Union[int, Tuple[int], Tuple[int, int]]) – The stride of the sliding window for each dimension of input.

  • padding (str) – “SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (str, default: 'NHWC') – “NHWC” or “NCHW”. Defaults to “NHWC”.

  • count_include_pad (bool, default: False) – Whether to include padding in the averaging calculation.

  • ceil_mode (bool, default: False) – Whether to use ceil or floor for creating the output shape.

  • divisor_override (Optional[int], default: None) – If given, it will be used as the divisor, otherwise kernel_size will be used.

  • 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 – The result of the max pooling operation.

Examples

>>> x = ivy.arange(12.).reshape((2, 1, 3, 2))
>>> print(x.max_pool2d((2, 2), (1, 1), 'SAME'))
ivy.array([[[[ 2,  3],
[ 4,  5],
[ 4,  5]]],
[[[ 8,  9],
[10, 11],
[10, 11]]]])
>>> x = ivy.arange(48.).reshape((2, 4, 3, 2))
>>> print(x.max_pool2d(3, 1, 'VALID'))
ivy.array([[[[16, 17]],
[[22, 23]]],
[[[40, 41]],
[[46, 47]]]])
avg_pool3d(kernel, strides, padding, /, *, data_format='NDHWC', count_include_pad=False, ceil_mode=False, divisor_override=None, out=None)[source]#

Compute a 3-D max pool given 5-D input x.

Parameters:
  • self (Array) – Input volume [batch_size,d,h,w,d_in].

  • kernel (Union[int, Tuple[int], Tuple[int, int, int]]) – Convolution filters [d,h,w].

  • strides (Union[int, Tuple[int], Tuple[int, int, int]]) – The stride of the sliding window for each dimension of input.

  • padding (str) – SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (str, default: 'NDHWC') – NDHWC” or “NCDHW”. Defaults to “NDHWC”.

  • count_include_pad (bool, default: False) – Whether to include padding in the averaging calculation.

  • ceil_mode (bool, default: False) – Whether to use ceil or floor for creating the output shape.

  • divisor_override (Optional[int], default: None) – If specified, it will be used as divisor, otherwise kernel_size will be used.

  • 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 – The result of the pooling operation.

Examples

>>> x = ivy.arange(48.).reshape((2, 3, 2, 2, 2))
>>> print(x.avg_pool3d(2, 2, 'VALID'))
ivy.array([[[[[ 7.,  8.]]]],
       [[[[31., 32.]]]]])
>>> print(x.avg_pool3d(2, 2, 'SAME'))
ivy.array([[[[[ 7.,  8.]]],
        [[[19., 20.]]]],
       [[[[31., 32.]]],
        [[[43., 44.]]]]])
dct(*, type=2, n=None, axis=-1, norm=None, out=None)[source]#

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

Parameters:
  • self (Array) – The input signal.

  • type (Literal[1, 2, 3, 4], default: 2) – The type of the dct. Must be 1, 2, 3 or 4.

  • n (Optional[int], default: None) – The length of the transform. If n is less than the input signal length, then x is truncated, if n is larger than x is zero-padded.

  • norm (Optional[Literal['ortho']], default: None) – The type of normalization to be applied. Must be either None or “ortho”.

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

Return type:

Array

Returns:

ret – Array containing the transformed input.

Examples

>>> x = ivy.array([8., 16., 24., 32., 40., 48., 56., 64.])
>>> x.dct(type=2, norm="ortho")
ivy.array([ 102.,  -51.5,   0.,  -5.39,   0.,  -1.61,   0., -0.406])
dft(*, axis=1, inverse=False, onesided=False, dft_length=None, norm='backward', out=None)[source]#

Compute the discrete Fourier transform of input.

Parameters:
  • self – Input volume […,d_in,…], where d_in indicates the dimension that needs FFT.

  • axis (int, default: 1) – The axis on which to perform the DFT. By default this value is set to 1, which corresponds to the first dimension after the batch index.

  • inverse (bool, default: False) – Whether to perform the inverse discrete fourier transform. By default this value is set to False.

  • onesided (bool, default: False) – If onesided is True, only values for w in [0, 1, 2, …, floor(n_fft/2) + 1] are returned because the real-to-complex Fourier transform satisfies the conjugate symmetry, i.e., X[m, w] = X[m,w]=X[m,n_fft-w]*. Note if the input or window tensors are complex, then onesided output is not possible. Enabling onesided with real inputs performs a Real-valued fast Fourier transform (RFFT). When invoked with real or complex valued input, the default value is False. Values can be True or False.

  • dft_length (Optional[Union[int, Tuple[int]]], default: None) – The length of the signal.If greater than the axis dimension, the signal will be zero-padded up to dft_length. If less than the axis dimension, only the first dft_length values will be used as the signal. It’s an optional value.

  • norm (str, default: 'backward') – Optional argument, “backward”, “ortho” or “forward”. Defaults to be “backward”. “backward” indicates no normalization. “ortho” indicates normalization by 1/sqrt(n). “forward” indicates normalization by 1/n.

  • 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 – The Fourier Transform of the input vector.If onesided is False, the following shape is expected: [batch_idx][signal_dim1][signal_dim2] …[signal_dimN][2]. If axis=0 and onesided is True, the following shape is expected: [batch_idx][floor(signal_dim1/2)+1][signal_dim2] …[signal_dimN][2]. If axis=1 and onesided is True, the following shape is expected: [batch_idx][signal_dim1] [floor(signal_dim2/2)+1] …[signal_dimN][2]. If axis=N-1 and onesided is True, the following shape is expected: [batch_idx][signal_dim1][signal_dim2]… [floor(signal_dimN/2)+1][2]. The signal_dim at the specified axis is equal to the dft_length.

embedding(indices, /, *, max_norm=None, out=None)[source]#
Return type:

Array

fft(dim, /, *, norm='backward', n=None, out=None)[source]#

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

Parameters:
  • self (Array) – Input volume […,d_in,…], where d_in indicates the dimension that needs FFT.

  • dim (int) – The dimension along which to take the one dimensional FFT.

  • norm (str, default: 'backward') – Optional argument, “backward”, “ortho” or “forward”. Defaults to be “backward”. “backward” indicates no normalization. “ortho” indicates normalization by 1/sqrt(n). “forward” indicates normalization by 1/n.

  • n (Optional[Union[int, Tuple[int]]], default: None) – Optional argument indicating the sequence length, if given, the input would be padded with zero or truncated to length n before performing FFT. Should be a integer greater than 1.

  • 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 – Array containing the transformed input.

Examples

>>> a = ivy.array((np.exp(2j * np.pi * np.arange(8) / 8)))
>>> a.fft(0)
ivy.array([-3.44509285e-16+1.14423775e-17j,  8.00000000e+00-8.11483250e-16j,
            2.33486982e-16+1.22464680e-16j,  0.00000000e+00+1.22464680e-16j,
            9.95799250e-17+2.33486982e-16j,  0.00000000e+00+7.66951701e-17j,
            1.14423775e-17+1.22464680e-16j,  0.00000000e+00+1.22464680e-16j])
fft2(*, s=None, dim=(-2, -1), norm='backward', out=None)[source]#

Compute the 2-dimensional discrete Fourier Transform.

Parameters:
  • x – Input volume […,d_in,…], where d_in indicates the dimension that needs FFT2.

  • s (Optional[Sequence[int]], default: None) – sequence of ints, optional Shape (length of each transformed axis) of the output (s[0] refers to axis 0, s[1] to axis 1, etc.). This corresponds to n for fft(x, n). Along each axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. If s is not given, the shape of the input along the axes specified by axes is used.

  • dim (Sequence[int], default: (-2, -1)) – Axes over which to compute the FFT2. If not given, the last two axes are used. A repeated index in axes means the transform over that axis is performed multiple times. A one-element sequence means that a one-dimensional FFT is performed.

  • norm (str, default: 'backward') – Optional argument, “backward”, “ortho” or “forward”. Defaults to be “backward”. “backward” indicates no normalization. “ortho” indicates normalization by 1/sqrt(n). “forward” indicates normalization by 1/n.

  • 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 – The result of the FFT2 operation.

Examples

>>> a = ivy.array([[0, 0, 0, 0, 0],
                [1, 1, 1, 1, 1],
                [2, 2, 2, 2, 2],
                [3, 3, 3, 3, 3],
                [4, 4, 4, 4, 4]])
>>> ivy.fft2(a)
array([[ 50.  +0.j        ,   0.  +0.j        ,   0.  +0.j        , # may vary
        0.  +0.j        ,   0.  +0.j        ],
    [-12.5+17.20477401j,   0.  +0.j        ,   0.  +0.j        ,
        0.  +0.j        ,   0.  +0.j        ],
    [-12.5 +4.0614962j ,   0.  +0.j        ,   0.  +0.j        ,
        0.  +0.j        ,   0.  +0.j        ],
    [-12.5 -4.0614962j ,   0.  +0.j        ,   0.  +0.j        ,
        0.  +0.j        ,   0.  +0.j        ],
    [-12.5-17.20477401j,   0.  +0.j        ,   0.  +0.j        ,
        0.  +0.j        ,   0.  +0.j        ]])
idct(*, type=2, n=None, axis=-1, norm=None, out=None)[source]#

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

Parameters:
  • self (Array) – The input signal.

  • type (Literal[1, 2, 3, 4], default: 2) – The type of the idct. Must be 1, 2, 3 or 4.

  • n (Optional[int], default: None) – The length of the transform. If n is less than the input signal length, then x is truncated, if n is larger than x is zero-padded.

  • norm (Optional[Literal['ortho']], default: None) – The type of normalization to be applied. Must be either None or “ortho”.

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

Return type:

Array

Returns:

ret – Array containing the transformed input.

Examples

>>> x = ivy.array([8., 16., 24., 32., 40., 48., 56., 64.])
>>> x.idct(type=2, norm="ortho")
ivy.array([ 79.49862671, -70.37691498,  30.00390816, -23.58938599,
    13.92713165, -10.078475  ,   5.19664812,  -1.95411837])
ifft(dim, *, norm='backward', n=None, out=None)[source]#

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

Parameters:
  • self (Array) – Input volume […,d_in,…], where d_in indicates the dimension that needs IFFT.

  • dim (int) – The dimension along which to take the one dimensional IFFT.

  • norm (str, default: 'backward') – Optional argument, “backward”, “ortho” or “forward”. Defaults to be “backward”. “backward” indicates no normalization. “ortho” indicates normalization by 1/sqrt(n). “forward” indicates normalization by 1/n.

  • n (Optional[Union[int, Tuple[int]]], default: None) – Optional argument indicating the sequence length, if given, the input would be padded with zero or truncated to length n before performing IFFT. Should be a integer greater than 1.

  • 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 – Array containing the transformed input.

Examples

>>> a = ivy.array((np.exp(2j * np.pi * np.arange(8) / 8)))
>>> a.ifft(0)
ivy.array([-4.30636606e-17+1.43029718e-18j,  0.00000000e+00+1.53080850e-17j,
            1.43029718e-18+1.53080850e-17j,  0.00000000e+00+9.58689626e-18j,
            1.24474906e-17+2.91858728e-17j,  0.00000000e+00+1.53080850e-17j,
            2.91858728e-17+1.53080850e-17j,  1.00000000e+00-1.01435406e-16j])
ifftn(s=None, axes=None, *, norm='backward', out=None)[source]#

Compute the N-dimensional inverse discrete Fourier Transform.

Parameters:
  • x – Input array of complex numbers.

  • s (Optional[Union[int, Tuple[int, ...]]], default: None) – sequence of ints, optional Shape (length of transformed axis) of the output (s[0] refers to axis 0, s[1] to axis 1, etc.). If given shape is smaller than that of the input, the input is cropped. If larger, input is padded with zeros. If s is not given, shape of input along axes specified by axes is used.

  • axes (Optional[Union[int, Tuple[int, ...]]], default: None) – axes over which to compute the IFFT. If not given, last len(s) axes are used, or all axes if s is also not specified. Repeated indices in axes means inverse transform over that axis is performed multiple times.

  • norm (str, default: 'backward') – Optional argument, “backward”, “ortho” or “forward”. Defaults to be “backward”. “backward” indicates no normalization. “ortho” indicates normalization by 1/sqrt(n). “forward” indicates normalization by 1/n.

  • 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 – The truncated or zero-padded input, transformed along the axes indicated by axes, or by a combination of s or x, as explained in the parameters section above.

Examples

>>> x = ivy.array([[0.24730653+0.90832391j, 0.49495562+0.9039565j,
...                 0.98193269+0.49560517j],
...                 [0.93280757+0.48075343j, 0.28526384+0.3351205j,
...                 0.2343787 +0.83528011j],
...                 [0.18791352+0.30690572j, 0.82115787+0.96195183j,
...                 0.44719226+0.72654048j]])
>>> y = ivy.ifftn(x)
>>> print(y)
ivy.array([[ 0.51476765+0.66160417j, -0.04319742-0.05411636j,
        -0.015561  -0.04216015j],
       [ 0.06310689+0.05347854j, -0.13392983+0.16052352j,
        -0.08371392+0.17252843j],
       [-0.0031429 +0.05421245j, -0.10446617-0.17747098j,
         0.05344324+0.07972424j]])
>>> x = ivy.array([[0.24730653+0.90832391j, 0.49495562+0.9039565j,
...                 0.98193269+0.49560517j],
...                 [0.93280757+0.48075343j, 0.28526384+0.3351205j,
...                 0.2343787 +0.83528011j],
...                 [0.18791352+0.30690572j, 0.82115787+0.96195183j,
...                 0.44719226+0.72654048j]])
>>> y = ivy.ifftn(x, s=[2, 1], axes=[0, 1], norm='ortho')
>>> print(y)
ivy.array([[ 0.8344667 +0.98222595j],
       [-0.48472244+0.30233797j]])
interpolate(size, /, *, mode='linear', scale_factor=None, recompute_scale_factor=None, align_corners=None, antialias=False, out=None)[source]#

Down/up samples the input to the given size. The algorithm used for interpolation is determined by mode.

Parameters:
  • self – Input array, Must have the shape [batch x channels x [optional depth] x [optional height] x width].

  • size (Union[Sequence[int], int]) – Output size.

  • mode (Literal['linear', 'bilinear', 'trilinear', 'nearest', 'area', 'nearest_exact', 'tf_area', 'bicubic'], default: 'linear') – Interpolation mode. Can be one of the following: - linear - bilinear - trilinear - nearest - area - tf_area - bicubic - mitchellcubic - lanczos3 - lanczos5 - gaussian

  • scale_factor (Optional[Union[int, Sequence[int]]], default: None) – Multiplier for spatial size that defines the output size (overwriting size).

  • align_corners (Optional[bool], default: None) – If True, the corner pixels of the input and output tensors are aligned, and thus preserving the values at the corner pixels. If False, the corner pixels are not aligned, and the interpolation uses edge value padding for out-of-boundary values. only has an effect when mode is ‘linear’, ‘bilinear’, ‘bicubic’ or ‘trilinear’. Default: False

  • antialias (bool, default: False) – If True, antialiasing is applied when downsampling an image. Supported modes: ‘bilinear’, ‘bicubic’.

  • 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:

resized array

max_pool1d(kernel, strides, padding, /, *, data_format='NWC', dilation=1, ceil_mode=False, out=None)[source]#

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

Parameters:
  • self (Array) – Input image [batch_size,w,d_in].

  • kernel (Union[int, Tuple[int, ...]]) – The size of the window for each dimension of the input tensor.

  • strides (Union[int, Tuple[int, ...]]) – The stride of the sliding window for each dimension of input.

  • padding (Union[str, int, Tuple[int], List[Tuple[int, int]]]) – “SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (str, default: 'NWC') – “NWC” or “NCW”. Defaults to “NWC”.

  • dilaton – The stride between elements within a sliding window, must be > 0.

  • ceil_mode (bool, default: False) – If True, ceil is used instead of floor to compute the output shape. This ensures that every element is covered by a sliding window.

  • 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 – The result of the max pooling operation.

Examples

>>> x = ivy.arange(0, 24.).reshape((2, 3, 4))
>>> print(x.max_pool1d(2, 2, 'SAME'))
ivy.array([[[ 4.,  5.,  6.,  7.],
        [ 8.,  9., 10., 11.]],
       [[16., 17., 18., 19.],
        [20., 21., 22., 23.]]])
>>> x = ivy.arange(0, 24.).reshape((2, 3, 4))
>>> print(x.max_pool1d(2, 2, 'VALID'))
ivy.array([[[ 4.,  5.,  6.,  7.]],
   [[16., 17., 18., 19.]]])
max_pool2d(kernel, strides, padding, /, *, data_format='NHWC', dilation=1, ceil_mode=False, out=None)[source]#

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

Parameters:
  • self (Array) – Input image [batch_size,h,w,d_in].

  • kernel (Union[int, Tuple[int, ...]]) – The size of the window for each dimension of the input tensor.

  • strides (Union[int, Tuple[int, ...]]) – The stride of the sliding window for each dimension of input.

  • padding (Union[str, int, Tuple[int], List[Tuple[int, int]]]) – “SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (str, default: 'NHWC') – “NHWC” or “NCHW”. Defaults to “NHWC”.

  • dilaton – The stride between elements within a sliding window, must be > 0.

  • ceil_mode (bool, default: False) – If True, ceil is used instead of floor to compute the output shape. This ensures that every element is covered by a sliding window.

  • 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 – The result of the max pooling operation.

Examples

>>> x = ivy.arange(12.).reshape((2, 1, 3, 2))
>>> print(x.max_pool2d((2, 2), (1, 1), 'SAME'))
ivy.array([[[[ 2.,  3.],
         [ 4.,  5.],
         [ 4.,  5.]]],
[[[ 8., 9.],

[10., 11.], [10., 11.]]]])

>>> x = ivy.arange(48.).reshape((2, 4, 3, 2))
>>> print(x.max_pool2d(3, 1, 'VALID'))
ivy.array([[[[16., 17.]],

[[22., 23.]]],

[[[40., 41.]],

[[46., 47.]]]])

max_pool3d(kernel, strides, padding, /, *, data_format='NDHWC', dilation=1, ceil_mode=False, out=None)[source]#

Compute a 3-D max pool given 5-D input x.

Parameters:
  • self (Array) – Input volume [batch_size,d,h,w,d_in].

  • kernel (Union[int, Tuple[int, ...]]) – Convolution filters [d,h,w].

  • strides (Union[int, Tuple[int, ...]]) – The stride of the sliding window for each dimension of input.

  • padding (Union[str, int, Tuple[int], List[Tuple[int, int]]]) – “SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (str, default: 'NDHWC') – NDHWC” or “NCDHW”. Defaults to “NDHWC”.

  • dilaton – The stride between elements within a sliding window, must be > 0.

  • ceil_mode (bool, default: False) – If True, ceil is used instead of floor to compute the output shape. This ensures that every element is covered by a sliding window.

  • 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 – The result of the pooling operation.

Examples

>>> x = ivy.arange(48.).reshape((2, 3, 2, 2, 2))
>>> print(x.max_pool3d(2, 2, 'VALID'))
ivy.array([[[[[14., 15.]]]],
   [[[[38., 39.]]]]])
>>> print(x.max_pool3d(2, 2, 'SAME'))
ivy.array([[[[[14., 15.]]],
    [[[22., 23.]]]],
   [[[[38., 39.]]],
    [[[46., 47.]]]]])
max_unpool1d(indices, kernel_size, /, *, strides=None, padding=0, data_format='NCW')[source]#

Compute a 1-D max unpooling given the 1-D pooled input x and its indices.

Parameters:
  • self (Array) – Pooled input image [batch_size, w, d_in].

  • indices (Array) – Indices obtained from the corresponding max pooling operation.

  • kernel_size (Union[Tuple[int], int]) – Size of the kernel i.e., the sliding window for each dimension of input. [w].

  • strides (Optional[Union[int, Tuple[int]]], default: None) – The stride of the sliding window for each dimension of input.

  • padding (Union[int, Tuple[int]], default: 0) – SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (Optional[str], default: 'NCW') – NWC” or “NCW”. Defaults to “NWC”.

Return type:

Array

Returns:

ret – The result of the unpooling operation.

reduce_window(init_value, computation, window_dimensions, /, *, window_strides=1, padding='VALID', base_dilation=1, window_dilation=1)[source]#

Apply a reduction function to all elements in each window of an array.

Parameters:
  • self (Array) – An array representing the base area on which the window is going to slide over.

  • init_value (Union[int, float]) – The starting value for the reduction.

  • computation (Callable) – The reduction function to apply to elements in each window.

  • window_dimensions (Union[int, Sequence[int]]) – A sequence containing the window dimensions.

  • window_strides (Union[int, Sequence[int]], default: 1) – A sequence containing the window strides.

  • padding (Union[str, int, Sequence[Tuple[int, int]]], default: 'VALID') – Either the string ‘SAME’ (padding with zeros evenly), the string ‘VALID’ (no padding), or a sequence of n (low, high) integer pairs that give the padding to apply before and after each spatial dimension.

  • base_dilation (Union[int, Sequence[int]], default: 1) – A sequence containing the base dilation values.

  • window_dilation (Union[int, Sequence[int]], default: 1) – A sequence containing the window dilation values.

Return type:

Array

Returns:

ret – The result of the pooling-like operation.

Examples

>>> x = ivy.array([[1, 2, 3, 4],
>>>                [5, 6, 7, 8],
>>>                [9, 10, 11, 12]])
>>> x.reduce_window(0, ivy.sum, (2, 2))
ivy.array([[32.]])
rfft(*, n=None, axis=-1, norm='backward', out=None)[source]#

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

Parameters:
  • self (Array) – input array. Must have a real-valued floating-point data type.

  • n (Optional[int], default: None) – length of the transformed axis of the input. If - n is greater than the length of the input array, the input array is zero-padded to length n. - n is less than the length of the input array, the input array is trimmed to length n. - n is not provided, the length of the transformed axis of the output must equal the length of the input along the axis specified by axis. Default is None.

  • axis (int, default: -1) – axis (dimension) over which to compute the Fourier transform. If not set, the last axis (dimension) is used. Default is -1.

  • norm (Literal['backward', 'ortho', 'forward'], default: 'backward') – normalization mode. Should be one of the following modes: - ‘backward’: no normalization. - ‘ortho’: normalize by 1/sqrt(n) (i.e., make the FFT orthonormal). - ‘forward’: normalize by 1/n. Default is backward.

  • 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 transformed along the axis (dimension) indicated by axis. The returned array must have a complex-valued floating-point data type determined by Type Promotion Rules.

Examples

>>> x = ivy.array([0,1,2])
>>> y = x.rfft()
>>> print(y)
ivy.array([ 3. +0.j       , -1.5+0.8660254j])
rfftn(s=None, axes=None, *, norm='backward', out=None)[source]#

Compute the n-dimensional discrete Fourier Transform.

Parameters:
  • self (Array) – Input array.

  • s (Optional[Sequence[int]], default: None) – Shape (length of each transformed axis) of the output.

  • axes (Optional[Sequence[int]], default: None) – Axes over which to compute the RFFT. If not given, the last len(s) axes are used.

  • norm (str, default: 'backward') – Normalization mode: “backward”, “ortho”, or “forward”.

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

Return type:

Array

Returns:

ret – The result of the RFFT operation.

sliding_window(window_size, /, *, stride=1, dilation=1, padding='VALID')[source]#

Slide a window of specified dimension over all elements of an array.

Parameters:
  • input – An array representing the base area on which the window is going to slide over.

  • window_size (Union[int, Tuple[int, int], Tuple[int, int, int]]) – Size of the sliding window for each dimension of the input.

  • stride (Union[int, Tuple[int, int]], default: 1) – The stride of the sliding window for each dimension of input

  • padding (Union[str, int, Sequence[Tuple[int, int]]], default: 'VALID') – Either the string ‘SAME’ (padding with zeros evenly), the string ‘VALID’ (no padding), or a sequence of n (low, high) integer pairs that give the padding to apply before and after each spatial dimension.

  • dilation (Union[int, Tuple[int, int]], default: 1) – The stride between elements within a sliding window, must be > 0.

Return type:

Array

Returns:

ret – The result of the sliding window operation.

Examples

>>> x = ivy.array([[1, 2, 3, 4],
>>>                [5, 6, 7, 8],
>>>                [9, 10, 11, 12]])
>>> x.sliding_window((2, 2))
ivy.array([[[ 1,  2,  5,  6],
            [ 2,  3,  6,  7],
            [ 3,  4,  7,  8]],

[[ 5, 6, 9, 10], [ 6, 7, 10, 11], [ 7, 8, 11, 12]]])

stft(frame_length, frame_step, /, *, fft_length=None, window_fn=None, pad_end=False, name=None, out=None)[source]#

Compute the Short-time Fourier Transform of signals.

Parameters:
  • self (Array) – Input Arrays.

  • frame_length (int) – An integer scalar Tensor. The window length in samples.

  • frame_step (int) – An integer scalar Tensor. The number of samples to step.

  • fft_length (Optional[int], default: None) – An integer scalar Tensor. The size of the FFT to apply. If not provided, uses the smallest power of 2 enclosing frame_length.

  • window_fn (Optional[Callable], default: None) – A callable that takes a window length and a dtype keyword argument and returns a [window_length] Tensor of samples in the provided datatype. If set to None, no windowing is used.

  • pad_end (Optional[bool], default: False) – Whether to pad the end of signals with zeros when the provided frame length and step produces a frame that lies partially past its end.

  • name (Optional[str], default: None) – An optional name for the operation.

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

Return type:

Array

Returns:

ret – A […, frames, fft_unique_bins] Tensor of complex64/complex128 STFT values where fft_unique_bins is fft_length // 2 + 1 (the unique components of the FFT).

class ivy.data_classes.array.experimental.linear_algebra._ArrayWithLinearAlgebraExperimental[source]#
_abc_impl = <_abc._abc_data object>#
adjoint(*, out=None)[source]#

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

Return type:

Array

Examples

>>> x = np.array([[1.-1.j, 2.+2.j],
                  [3.+3.j, 4.-4.j]])
>>> x = ivy.array(x)
>>> x.adjoint()
ivy.array([[1.+1.j, 3.-3.j],
           [2.-2.j, 4.+4.j]])
batched_outer(tensors, /, *, out=None)[source]#

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

Parameters:

tensors (Sequence[Union[Array, NativeArray]]) – list of tensors of shape (n_samples, J1, …, JN) , (n_samples, K1, …, KM) …

Return type:

Array

Returns:

outer product of tensors – of shape (n_samples, J1, …, JN, K1, …, KM, …)

Examples

>>> a = ivy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
>>> b = ivy.array([[[.1, .2], [.3, .4]], [[.5, .6], [.7, .8]]])
>>> result = ivy.batched_outer(a, b)
>>> print(result)
ivy.array([[[[[0.1, 0.2],
      [0.30000001, 0.40000001]],
     [[0.2       , 0.40000001],
      [0.60000002, 0.80000001]]],
    [[[0.3       , 0.60000001],
      [0.90000004, 1.20000002]],
     [[0.40000001, 0.80000001],
      [1.20000005, 1.60000002]]]],
   [[[[2.5       , 3.00000012],
      [3.49999994, 4.00000006]],
     [[3.        , 3.60000014],
      [4.19999993, 4.80000007]]],
    [[[3.5       , 4.20000017],
      [4.89999992, 5.60000008]],
     [[4.        , 4.80000019],
      [5.5999999 , 6.4000001 ]]]]])
cond(*, p=None)[source]#

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

Return type:

Array

Examples

>>> x = ivy.array([[1,2], [3,4]])
>>> x.cond()
ivy.array(14.933034373659268)
>>> x = ivy.array([[1,2], [3,4]])
>>> x.cond(p=ivy.inf)
ivy.array(21.0)
diagflat(*, offset=0, padding_value=0, align='RIGHT_LEFT', num_rows=-1, num_cols=-1, out=None)[source]#

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

Return type:

Array

Examples

>>> x = ivy.array([1,2])
>>> x.diagflat(k=1)
ivy.array([[0, 1, 0],
           [0, 0, 2],
           [0, 0, 0]])
dot(b, /, *, out=None)[source]#

Compute the dot product between two arrays a and b using the current backend’s implementation. The dot product is defined as the sum of the element- wise product of the input arrays.

Parameters:
  • self (Union[Array, NativeArray]) – First input array.

  • b (Union[Array, NativeArray]) – Second input array.

  • out (Optional[Array], default: None) – Optional output array. If provided, the output array to store the result.

Returns:

ret – The dot product of the input arrays.

Examples

With ivy.Array inputs:

>>> a = ivy.array([1, 2, 3])
>>> b = ivy.array([4, 5, 6])
>>> result = ivy.dot(a, b)
>>> print(result)
ivy.array(32)
>>> a = ivy.array([[1, 2], [3, 4]])
>>> b = ivy.array([[5, 6], [7, 8]])
>>> c = ivy.empty_like(a)
>>> ivy.dot(a, b, out=c)
>>> print(c)
ivy.array([[19, 22],
    [43, 50]])
>>> a = ivy.array([[1.1, 2.3, -3.6]])
>>> b = ivy.array([[-4.8], [5.2], [6.1]])
>>> c = ivy.zeros((1, 1))
>>> ivy.dot(a, b, out=c)
>>> print(c)
ivy.array([[-15.28]])
eig()[source]#

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

Return type:

Tuple[Array, ...]

Examples

>>> x = ivy.array([[1,2], [3,4]])
>>> x.eig()
(
ivy.array([-0.37228132+0.j,  5.37228132+0.j]),
ivy.array([[-0.82456484+0.j, -0.41597356+0.j],
           [ 0.56576746+0.j, -0.90937671+0.j]])
)
eigh_tridiagonal(beta, /, *, eigvals_only=True, select='a', select_range=None, tol=None)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – An array of real or complex arrays each of shape (n), the diagonal elements of the matrix.

  • beta (Union[Array, NativeArray]) – An array or of real or complex arrays each of shape (n-1), containing the elements of the first super-diagonal of the matrix.

  • eigvals_only (bool, default: True) – If False, both eigenvalues and corresponding eigenvectors are computed. If True, only eigenvalues are computed. Default is True.

  • select (str, default: 'a') – Optional string with values in {‘a’, ‘v’, ‘i’} (default is ‘a’) that determines which eigenvalues to calculate: ‘a’: all eigenvalues. ‘v’: eigenvalues in the interval (min, max] given by select_range. ‘i’: eigenvalues with indices min <= i <= max.

  • select_range (Optional[Union[Tuple[int, int], List[int], Array, NativeArray]], default: None) – Size 2 tuple or list or array specifying the range of eigenvalues to compute together with select. If select is ‘a’, select_range is ignored.

  • tol (Optional[float], default: None) – Optional scalar. Ignored when backend is not Tensorflow. The absolute tolerance to which each eigenvalue is required. An eigenvalue (or cluster) is considered to have converged if it lies in an interval of this width. If tol is None (default), the value eps*|T|_2 is used where eps is the machine precision, and |T|_2 is the 2-norm of the matrix T.

Return type:

Union[Array, Tuple[Array, Array]]

Returns:

  • eig_vals – The eigenvalues of the matrix in non-decreasing order.

  • eig_vectors – If eigvals_only is False the eigenvectors are returned in the second output argument.

Examples

>>> alpha = ivy.array([0., 1., 2.])
>>> beta = ivy.array([0., 1.])
>>> y = alpha.eigh_tridiagonal(beta)
>>> print(y)
ivy.array([0., 0.38196, 2.61803])
eigvals()[source]#

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

Return type:

Array

Examples

>>> x = ivy.array([[1,2], [3,4]])
>>> x.eigvals()
ivy.array([-0.37228132+0.j,  5.37228132+0.j])
general_inner_product(b, n_modes=None, /, *, out=None)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – first input tensor.

  • b (Union[Array, NativeArray]) – second input tensor.

  • n_modes (Optional[int], default: None) – int, default is None. If None, the traditional inner product is returned (i.e. a float) otherwise, the product between the n_modes last modes of a and the n_modes first modes of b is returned. The resulting tensor’s order is len(a) - n_modes.

  • out (Optional[Array], default: None) – Optional output array. If provided, the output array to store the result.

Return type:

Array

Returns:

The inner product of the input arrays.

Examples

With ivy.Array inputs:

>>> a = ivy.array([1, 2, 3])
>>> b = ivy.array([4, 5, 6])
>>> result = a.general_inner_product(b, 1)
>>> print(result)
ivy.array(32)
>>> a = ivy.array([1, 2])
>>> b = ivy.array([4, 5])
>>> result = a.general_inner_product(b)
>>> print(result)
ivy.array(14)
>>> a = ivy.array([[1, 1], [1, 1]])
>>> b = ivy.array([[1, 2, 3, 4],[1, 1, 1, 1]])
>>> result = a.general_inner_product(b, 1)
>>> print(result)
ivy.array([[2, 3, 4, 5],
    [2, 3, 4, 5]])
higher_order_moment(order, /, *, out=None)[source]#

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

Parameters:
  • x – matrix of size (n_samples, n_features) or tensor of size(n_samples, D1, …, DN)

  • order (int) – number of the higher-order moment to compute

Return type:

Array

Returns:

tensor – if tensor is a matrix of size (n_samples, n_features), tensor of size (n_features, )*order

Examples

>>> a = ivy.array([[1, 2], [3, 4]])
>>> result = ivy.higher_order_moment(a, 3)
>>> print(result)
ivy.array([[
    [14, 19],
    [19, 26]],
   [[19, 26],
    [26, 36]
]])
initialize_tucker(rank, modes, /, *, init='svd', seed=None, svd='truncated_svd', non_negative=False, mask=None, svd_mask_repeats=5)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – input tensor

  • rank (Sequence[int]) – number of components

  • modes (Sequence[int]) – modes to consider in the input tensor

  • seed (Optional[int], default: None) – Used to create a random seed distribution when init == ‘random’

  • init (Optional[Union[Literal['svd', 'random'], TuckerTensor]], default: 'svd') – initialization scheme for tucker decomposition.

  • svd (Optional[Literal['truncated_svd']], default: 'truncated_svd') – function to use to compute the SVD

  • non_negative (Optional[bool], default: False) – if True, non-negative factors are returned

  • mask (Optional[Union[Array, NativeArray]], default: None) – array of booleans with the same shape as tensor should be 0 where the values are missing and 1 everywhere else. Note: if tensor is sparse, then mask should also be sparse with a fill value of 1 (or True).

  • svd_mask_repeats (Optional[int], default: 5) – number of iterations for imputing the values in the SVD matrix when mask is not None

Return type:

Tuple[Array, Sequence[Array]]

Returns:

  • core – initialized core tensor

  • factors – list of factors

kron(b, /, *, out=None)[source]#

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

Return type:

Array

Examples

>>> a = ivy.array([1,2])
>>> b = ivy.array([3,4])
>>> a.diagflat(b)
ivy.array([3, 4, 6, 8])
make_svd_non_negative(U, S, V, /, *, nntype='nndsvd')[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – tensor being decomposed.

  • U (Union[Array, NativeArray]) – left singular matrix from SVD.

  • S (Union[Array, NativeArray]) – diagonal matrix from SVD.

  • V (Union[Array, NativeArray]) – right singular matrix from SVD.

  • nntype (Optional[Literal['nndsvd', 'nndsvda']], default: 'nndsvd') – whether to fill small values with 0.0 (nndsvd), or the tensor mean (nndsvda, default).

  • [1] (Boutsidis & Gallopoulos. Pattern Recognition, 41(4): 1350-1362, 2008.) –

Return type:

Tuple[Array, Array]

matrix_exp(*, out=None)[source]#

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

Return type:

Array

Examples

>>> x = ivy.array([[[1., 0.],
                    [0., 1.]],
                    [[2., 0.],
                    [0., 2.]]])
>>> ivy.matrix_exp(x)
ivy.array([[[2.7183, 1.0000],
            [1.0000, 2.7183]],
            [[7.3891, 1.0000],
            [1.0000, 7.3891]]])
mode_dot(matrix_or_vector, mode, transpose=False, *, out=None)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – tensor of shape (i_1, ..., i_k, ..., i_N)

  • matrix_or_vector (Union[Array, NativeArray]) – 1D or 2D array of shape (J, i_k) or (i_k, ) matrix or vectors to which to n-mode multiply the tensor

  • mode (int) – int in the range(1, N)

  • transpose (Optional[bool], default: False) – If True, the matrix is transposed. For complex tensors, the conjugate transpose is used.

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

Return type:

Array

Returns:

ivy.Arraymode-mode product of tensor by matrix_or_vector * of shape \((i_1, ..., i_{k-1}, J, i_{k+1}, ..., i_N)\) if matrix_or_vector is a matrix * of shape \((i_1, ..., i_{k-1}, i_{k+1}, ..., i_N)\) if matrix_or_vector is a vector

multi_dot(x, /, *, out=None)[source]#

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

Return type:

Array

Examples

>>> A = ivy.arange(2 * 3).reshape((2, 3))
>>> B = ivy.arange(3 * 2).reshape((3, 2))
>>> C = ivy.arange(2 * 2).reshape((2, 2))
>>> A.multi_dot((B, C))
ivy.array([[ 26,  49],
           [ 80, 148]])
multi_mode_dot(mat_or_vec_list, /, modes=None, skip=None, transpose=False, *, out=None)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – the input tensor

  • mat_or_vec_list (Sequence[Union[Array, NativeArray]]) – sequence of matrices or vectors of length tensor.ndim

  • skip (Optional[Sequence[int]], default: None) – None or int, optional, default is None If not None, index of a matrix to skip.

  • modes (Optional[Sequence[int]], default: None) – None or int list, optional, default is None

  • transpose (Optional[bool], default: False) – If True, the matrices or vectors in in the list are transposed. For complex tensors, the conjugate transpose is used.

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

Return type:

Array

Returns:

ivy.Array – tensor times each matrix or vector in the list at mode mode

Notes

If no modes are specified, just assumes there is one matrix or vector per mode and returns: \(\\text{x }\\times_0 \\text{ matrix or vec list[0] }\\times_1 \\cdots \\times_n \\text{ matrix or vec list[n] }\)

partial_tucker(rank=None, modes=None, /, *, n_iter_max=100, init='svd', svd='truncated_svd', seed=None, mask=None, svd_mask_repeats=5, tol=0.0001, verbose=False, return_errors=False)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – the input tensor

  • rank (Optional[Sequence[int]], default: None) – size of the core tensor, (len(ranks) == tensor.ndim) if int, the same rank is used for all modes if None, original tensors size will be preserved.

  • modes (Optional[Sequence[int]], default: None) – list of the modes on which to perform the decomposition

  • n_iter_max (Optional[int], default: 100) – maximum number of iteration

  • init (Optional[Union[Literal['svd', 'random'], TuckerTensor]], default: 'svd') – {‘svd’, ‘random’}, or TuckerTensor optional if a TuckerTensor is provided, this is used for initialization

  • svd (Optional[Literal['truncated_svd']], default: 'truncated_svd') – str, default is ‘truncated_svd’ function to use to compute the SVD,

  • seed (Optional[int], default: None) – Used to create a random seed distribution when init == ‘random’

  • mask (Optional[Union[Array, NativeArray]], default: None) – array of booleans with the same shape as tensor should be 0 where the values are missing and 1 everywhere else. Note: if tensor is sparse, then mask should also be sparse with a fill value of 1 (or True).

  • svd_mask_repeats (Optional[int], default: 5) – number of iterations for imputing the values in the SVD matrix when mask is not None

  • tol (Optional[float], default: 0.0001) – tolerance: the algorithm stops when the variation in the reconstruction error is less than the tolerance.

  • verbose (Optional[bool], default: False) – if True, different in reconstruction errors are returned at each iteration.

  • return_erros – if True, list of reconstruction errors are returned.

Return type:

Tuple[Array, Sequence[Array]]

Returns:

  • core (ndarray) – core tensor of the Tucker decomposition

  • factors (ndarray list) – list of factors of the Tucker decomposition. with core.shape[i] == (tensor.shape[i], ranks[i]) for i in modes

svd_flip(V, /, u_based_decision=True)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – left singular matrix output of SVD

  • V (Union[Array, NativeArray]) – right singular matrix output of SVD

  • u_based_decision (Optional[bool], default: True) – If True, use the columns of u as the basis for sign flipping. Otherwise, use the rows of v. The choice of which variable to base the decision on is generally algorithm dependent.

Return type:

Tuple[Array, Array]

Returns:

u_adjusted, v_adjusted (arrays with the same dimensions as the input.)

tensor_train(rank, /, svd='truncated_svd', verbose=False)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – input tensor

  • rank (Union[int, Sequence[int]]) – maximum allowable TT rank of the factors if int, then this is the same for all the factors if int list, then rank[k] is the rank of the kth factor

  • svd (Optional[Literal['truncated_svd']], default: 'truncated_svd') – function to use to compute the SVD

  • verbose (Optional[bool], default: False) – level of verbosity

Return type:

TTTensor

Returns:

ivy.TTTensor

truncated_svd(compute_uv=True, n_eigenvecs=None)[source]#

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

Parameters:
  • x – 2D-array

  • compute_uv (bool, default: True) – If True then left and right singular vectors will be computed and returnedv in U and Vh respectively. Otherwise, only the singular values will be computed, which can be significantly faster.

  • n_eigenvecs (Optional[int], default: None) – if specified, number of eigen[vectors-values] to return else full matrices will be returned

Return type:

Union[Array, Tuple[Array, Array, Array]]

Returns:

ret – a namedtuple (U, S, Vh) Each returned array must have the same floating-point data type as x.

tt_matrix_to_tensor(*, out=None)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – array of 4D-arrays TT-Matrix factors (known as core) of shape (rank_k, left_dim_k, right_dim_k, rank_{k+1})

  • out (Optional[Array], default: None) – Optional output array. If provided, the output array to store the result.

Return type:

Array

Returns:

>>> a = ivy.array([[[[[0.49671414],
...                      [-0.1382643]],
...
...                     [[0.64768857],
...                      [1.5230298]]]],
...                   [[[[-0.23415337],
...                      [-0.23413695]],
...
...                     [[1.57921278],
...                      [0.76743472]]]]])
>>> a.tt_matrix_to_tensor()
ivy.array([[[[-0.1163073 , -0.11629914],
 [ 0.03237505,  0.03237278]],
[[ 0.78441733, 0.38119566],

[-0.21834874, -0.10610882]]],

[[[-0.15165846, -0.15164782],

[-0.35662258, -0.35659757]],

[[ 1.02283812, 0.49705869],

[ 2.40518808, 1.16882598]]]])

tucker(rank=None, /, *, fixed_factors=None, n_iter_max=100, init='svd', svd='truncated_svd', seed=None, mask=None, svd_mask_repeats=5, tol=0.0001, verbose=False, return_errors=False)[source]#

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

Parameters:
  • x – input tensor

  • rank (Optional[Sequence[int]], default: None) – size of the core tensor, (len(ranks) == tensor.ndim) if int, the same rank is used for all modes

  • fixed_factors (Optional[Sequence[int]], default: None) – if not None, list of modes for which to keep the factors fixed. Only valid if a Tucker tensor is provided as init.

  • n_iter_max (Optional[int], default: 100) – maximum number of iteration

  • init (Optional[Union[Literal['svd', 'random'], TuckerTensor]], default: 'svd') – {‘svd’, ‘random’}, or TuckerTensor optional if a TuckerTensor is provided, this is used for initialization

  • svd (Optional[Literal['truncated_svd']], default: 'truncated_svd') – str, default is ‘truncated_svd’ function to use to compute the SVD,

  • seed (Optional[int], default: None) – Used to create a random seed distribution when init == ‘random’

  • mask (Optional[Union[Array, NativeArray]], default: None) – array of booleans with the same shape as tensor should be 0 where the values are missing and 1 everywhere else. Note: if tensor is sparse, then mask should also be sparse with a fill value of 1 (or True).

  • svd_mask_repeats (Optional[int], default: 5) – number of iterations for imputing the values in the SVD matrix when mask is not None

  • tol (Optional[float], default: 0.0001) – tolerance: the algorithm stops when the variation in the reconstruction error is less than the tolerance

  • verbose (Optional[bool], default: False) – if True, different in reconstruction errors are returned at each iteration.

  • return_errors (Optional[bool], default: False) – Indicates whether the algorithm should return all reconstruction errors and computation time of each iteration or not Default: False

Returns:

ivy.TuckerTensor or ivy.TuckerTensor and list of reconstruction errors if return_erros is True.

References

SIAM REVIEW, vol. 51, n. 3, pp. 455-500, 2009.

class ivy.data_classes.array.experimental.losses._ArrayWithLossesExperimental[source]#
_abc_impl = <_abc._abc_data object>#
hinge_embedding_loss(target, *, margin=1.0, reduction='mean')[source]#

Measures loss from input x and label y with values 1 or -1. It evaluates if two inputs are similar or not, often used for embedding or semi-supervised learning.

Loss for the n-th sample:
\[\begin{split}l_n = \begin{cases} x_n, & \text{if}\; y_n = 1,\\ \max \{0, margin - x_n\}, & \text{if}\; y_n = -1, \end{cases}\end{split}\]
Total loss:
\[\begin{split}\ell(x, y) = \begin{cases} \operatorname{mean}(L), & \text{if reduction} = \text{`mean';}\\ \operatorname{sum}(L), & \text{if reduction} = \text{`sum'.} \end{cases}\end{split}\]

where \(L = \{l_1,\dots,l_N\}^\top\)

Parameters:
  • input – Input tensor with dtype float. The shape is [N, *], where N is batch size and * represents any number of additional dimensions.

  • label – Label tensor containing 1 or -1 with dtype float32 or float64. Its shape matches that of the input.

  • margin (float, default: 1.0) – Sets the hyperparameter margin. Determines the necessary input size for hinge_embedding_loss calculations when label is -1. Inputs smaller than the margin are minimized with hinge_embedding_loss. Default is 1.0.

  • reduction (str, default: 'mean') – Specifies how to aggregate the loss across the batch. Options are: - 'none': Returns the unreduced loss. - 'mean': Returns the mean loss. - 'sum': Returns the summed loss. Default is 'mean'.

  • Shape

  • -----

    • Input: \((*)\) where \(*\) means, any number of dimensions.

    The sum operation operates over all the elements. - Target: \((*)\), same shape as the input - Output: scalar. If reduction is 'none', then same shape as the input

Return type:

Array

Returns:

ret – Hinge embedding loss calculated from the input and label, shaped based on the reduction method.

Examples

>>> input_tensor = ivy.array([1, 2, 3, 4], dtype=ivy.float64)
>>> target_tensor = ivy.array([1, 1, 1, 1], dtype=ivy.float64)
>>> input_tensor.hinge_embedding_loss(target_tensor,reduction="sum")
ivy.array(10.)
>>> input_tensor = ivy.array([1, 2, 3], dtype=ivy.float64)
>>> target_tensor = ivy.array([1, -1, -1], dtype=ivy.float64)
>>> input_tensor.hinge_embedding_loss(target_tensor, margin=2.0)
ivy.array(0.33333333)
huber_loss(target, /, *, reduction='mean', delta=1.0, out=None)[source]#

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

Parameters:
  • self (Array) – input array containing true labels.

  • target (Union[Array, NativeArray]) – input array containing targeted labels.

  • reduction (str, optional) – The type of reduction to apply to the loss. Possible values are “mean” (default) and “sum”.

  • delta (Optional[float], default: 1.0) – The threshold parameter that determines the point where the loss transitions from squared error to absolute error. Default is 1.0.

  • 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 – The Huber loss between the true and predicted values.

Examples

>>> true = ivy.array([2, 4, 7, 1])
>>> pred = ivy.array([2.5, 3.5, 8, 0.8])
>>> loss = true.huber_loss(pred, delta=1.0)
>>> print(loss)
ivy.array([0.125, 0.125, 0.5  , 0.125])
kl_div(target, /, *, reduction='mean', log_target=False, out=None)[source]#

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

Parameters:
  • self (Array) – Array containing input probability distribution.

  • target (Union[Array, NativeArray]) – Array contaiing target probability distribution.

  • reduction (Optional[str], default: 'mean') – ‘none’: No reduction will be applied to the output. ‘mean’: The output will be averaged. ‘batchmean’: The output will be divided by batch size. ‘sum’: The output will be summed. Default: ‘mean’.

  • 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 – The Kullback-Leibler divergence loss between the two input arrays.

Examples

>>> input = ivy.array([0.2, 0.8], [0.5, 0.5])
>>> target = ivy.array([0.6, 0.4], [0.3, 0.7])
>>> output_array = input.kl_div(target)
>>> print(output_array)
ivy.array(0.0916)
l1_loss(target, /, *, reduction='mean', out=None)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – input array containing true labels.

  • target (Union[Array, NativeArray]) – input array containing targeted labels.

  • reduction (Optional[str], default: 'mean') – 'mean': The output will be averaged. 'sum': The output will be summed. 'none': No reduction will be applied to the output. Default: 'mean'.

  • 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 – The L1 loss between the input array and the targeticted values.

Examples

>>> x = ivy.array([1.0, 2.0, 3.0])
>>> y = ivy.array([0.7, 1.8, 2.9])
>>> z = x.l1_loss(y)
>>> print(z)
ivy.array(0.20000000000000004)
log_poisson_loss(target, /, *, compute_full_loss=False, axis=-1, reduction='none', out=None)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – input array containing true labels.

  • target (Union[Array, NativeArray]) – input array containing targeted labels.

  • compute_full_loss (bool, default: False) – whether to compute the full loss. If false, a constant term is dropped in favor of more efficient optimization. Default: False.

  • axis (int, default: -1) – the axis along which to compute the log-likelihood loss. If axis is -1, the log-likelihood loss will be computed along the last dimension. Default: -1.

  • reduction (str, default: 'none') – 'none': No reduction will be applied to the output. 'mean': The output will be averaged. 'sum': The output will be summed. Default: 'none'.

  • 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 – The binary log-likelihood loss between the given distributions.

Examples

>>> x = ivy.array([0, 0, 1, 0])
>>> y = ivy.array([0.25, 0.25, 0.25, 0.25])
>>> loss = x.log_poisson_loss(y)
>>> print(loss)
ivy.array([1.28402555, 1.28402555, 1.03402555, 1.28402555])
>>> z = ivy.array([0.1, 0.1, 0.7, 0.1])
>>> loss = x.log_poisson_loss(z, reduction='mean')
>>> print(loss)
ivy.array(1.1573164)
poisson_nll_loss(target, *, log_input=True, full=False, eps=1e-08, reduction='mean')[source]#

Compute the Poisson Negative Log Likelihood Loss.

This function calculates the negative log likelihood loss between the input and target`under the assumption that the target follows a Poisson distribution. By default, the loss is not the exact loss, but the loss minus a constant term [log(z!)]. This omission does not affect optimization but can be significant for relative loss comparisons. The Stirling’s Approximation is used to approximate the log factorial term when `full is set to True.

Parameters:
  • input – Expectation of the underlying Poisson distribution.

  • target (Union[Array, NativeArray]) – Random sample from the Poisson distribution described by the input.

  • log_input (bool, default: True) – If True, the loss is computed as \(exp(input) - target * input\). If False, the loss is computed as \(input - target * log(input + eps)\). Default is True.

  • full (bool, default: False) – Whether to compute the full loss, i.e., to add the Stirling approximation term \(target * log(target) - target + 0.5 * log(2 * pi * target)\). Default is False.

  • eps (float, default: 1e-08) – Small value to prevent evaluation of log(0) when log_input is False. Default is 1e-8.

  • reduction (str, default: 'mean') – Specifies the reduction applied to the output. Options are ‘none’, ‘mean’, or ‘sum’. ‘none’: no reduction will be applied. ‘mean’: the output will be averaged. ‘sum’: the output will be summed. Default is ‘mean’.

Return type:

Array

Returns:

ret – An array of the same shape as input representing the Poisson Negative Log Likelihood Loss.

Raises:

ValueError – If the input and target tensors do not have the same shape.

Examples

>>> input_tensor = ivy.array([1, 2, 3, 4], dtype=ivy.float64)
>>> target_tensor = ivy.array([2, 2, 2, 2], dtype=ivy.float64)
>>> loss = input_tensor.poisson_nll_loss(target_tensor, log_input=True)
>>> print(loss)
ivy.array(16.1977562)
smooth_l1_loss(target, /, *, beta=1.0, reduction='mean', out=None)[source]#

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

Parameters:
  • self (Array) – input array containing true labels.

  • target (Union[Array, NativeArray]) – input array containing targeted labels.

  • beta (Optional[float], default: 1.0) – A float specifying the beta value for the smooth L1 loss. Default: 1.0.

  • reduction (Optional[str], default: 'mean') – Reduction method for the loss. Options are ‘none’, ‘mean’, or ‘sum’. Default: ‘mean’.

  • 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 – The smooth L1 loss between the given labels.

Examples

>>> x = ivy.array([1, 2, 3, 4])
>>> y = ivy.array([2, 2, 2, 2])
>>> z = x.smooth_l1_loss(y, beta=0.5)
>>> print(z)
ivy.array(0.8125)
soft_margin_loss(target, /, *, reduction='mean', out=None)[source]#

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

Parameters:
  • self (Array) – input array containing true labels.

  • target (Union[Array, NativeArray]) – input array containing targeted labels.

  • reduction (Optional[str], default: 'mean') – 'none': No reduction will be applied to the output. 'mean': The output will be averaged. 'sum': The output will be summed. Default: 'sum'.

  • 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 – The soft margin loss between the true and targeticted labels.

Examples

>>> x = ivy.array([1, 1, 0])
>>> y = ivy.array([0.7, 0.8, 0.2])
>>> z = x.soft_margin_loss(y)
>>> print(z)
ivy.array([0.35667497, 0.22314353, 1.60943791])
class ivy.data_classes.array.experimental.manipulation._ArrayWithManipulationExperimental[source]#
_abc_impl = <_abc._abc_data object>#
as_strided(shape, strides, /)[source]#

Create a copy of the input array with the given shape and strides.

Parameters:
  • self (Array) – Input Array.

  • shape (Union[Shape, NativeShape, Sequence[int]]) – The shape of the new array.

  • strides (Sequence[int]) – The strides of the new array (specified in bytes).

Return type:

Array

Returns:

ret – Output Array

associative_scan(fn, /, *, reverse=False, axis=0)[source]#

Perform an associative scan over the given array.

Parameters:
  • self (Array) – The array to scan over.

  • fn (Callable) – The associative function to apply.

  • reverse (bool, default: False) – Whether to scan in reverse with respect to the given axis.

  • axis (int, default: 0) – The axis to scan over.

Return type:

Array

Returns:

ret – The result of the scan.

atleast_1d(*arys, copy=None)[source]#

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

Parameters:
  • self (Array) – Input array. Cannot be a scalar input.

  • arys (Union[Array, bool, Number]) – An arbitrary number of input arrays.

  • copy (Optional[bool], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning a view of the input array.

Return type:

List[Array]

Returns:

ret – List of arrays, each with a.ndim >= 1. Copies are made only if necessary.

Examples

>>> a1 = ivy.array([[1,2,3]])
>>> a2 = ivy.array(4)
>>> a1.atleast_1d(a2,5,6)
[ivy.array([[1, 2, 3]]), ivy.array([4]), ivy.array([5]), ivy.array([6])]
atleast_2d(*arys, copy=None)[source]#

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

Parameters:
  • self (Array) – Input array. Cannot be a scalar input.

  • arys (Array) – An arbitrary number of input arrays.

  • copy (Optional[bool], default: None) –

    boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning

    a view of the input array.

Return type:

List[Array]

Returns:

ret – List of arrays, each with a.ndim >= 2. Copies are made only if necessary.

Examples

>>> a1 = ivy.array([[1,2,3]])
>>> a2 = ivy.array(4)
>>> a1.atleast_2d(a2,5,6)
[ivy.array([[1, 2, 3]]), ivy.array([[4]]), ivy.array([[5]]), ivy.array([[6]])]
atleast_3d(*arys, copy=None)[source]#

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

Parameters:
  • self (Array) – Input array. Cannot be a scalar input.

  • arys (Union[Array, bool, Number]) – An arbitrary number of input arrays.

  • copy (Optional[bool], default: None) –

    boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning

    a view of the input array.

Return type:

List[Array]

Returns:

ret – List of arrays, each with a.ndim >= 3. Copies are made only if necessary and views with three or more dimensions are returned. For example, a 1-D array of shape (N,) becomes a view of shape (1, N, 1), and a 2-D array of shape (M, N) becomes a view of shape (M, N, 1).

Examples

>>> a1 = ivy.array([[1,2,3]])
>>> a2 = ivy.array([4,8])
>>> a1.atleast_3d(a2,5,6)
[ivy.array([[[1],
        [2],
        [3]]]), ivy.array([[[4],
        [8]]]), ivy.array([[[5]]]), ivy.array([[[6]]])]
column_stack(arrays, /, *, out=None)[source]#

ivy.Array instance method variant of ivy.column_stack.

This method simply wraps the function, and so the docstring for ivy.column_stack also applies to this method with minimal changes.

Parameters:
  • self (Array) – Array that will be stacked at the beginning of the provided array iterable.

  • arrays (Sequence[Union[Array, NativeArray]]) – Arrays to be stacked.

  • out (Optional[Array], default: None) – Output array.

Return type:

Array

Returns:

ret – Stacked input.

concat_from_sequence(input_sequence, *, new_axis=0, axis=0, out=None)[source]#

Concatenate a sequence of arrays along a new or an existing axis.

Parameters:
  • self (Array) – Array input.

  • input_sequence (Union[Tuple[Union[Array, NativeArray]], List[Union[Array, NativeArray]]]) – A sequence of arrays.

  • new_axis (int, default: 0) – Insert and concatenate on a new axis or not, default 0 means do not insert new axis. new_axis = 0: concatenate new_axis = 1: stack

  • axis (int, default: 0) – The axis along which the arrays will be concatenated.

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

Return type:

Array

Returns:

ret – Output Array

dsplit(indices_or_sections, /, *, copy=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • indices_or_sections (Union[int, Sequence[int], Array]) – If indices_or_sections is an integer n, the array is split into n equal sections, provided that n must be a divisor of the split axis. If indices_or_sections is a sequence of ints or 1-D array, then input is split at each of the indices.

  • copy (Optional[bool], default: None) –

    boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning

    a view of the input array.

Return type:

List[Array]

Returns:

ret – input array split along the 3rd axis.

Examples

>>> ary = ivy.array(
    [[[ 0.,   1.,   2.,   3.],
      [ 4.,   5.,   6.,   7.]],
     [[ 8.,   9.,  10.,  11.],
      [12.,  13.,  14.,  15.]]]
)
>>> ary.dsplit(2)
[ivy.array([[[ 0.,  1.], [ 4.,  5.]], [[ 8.,  9.], [12., 13.]]]),
ivy.array([[[ 2.,  3.], [ 6.,  7.]], [[10., 11.], [14., 15.]]])]
dstack(arrays, /, *, out=None)[source]#

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

Return type:

Array

Examples

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.array([2, 3, 4])
>>> x.dstack(y)
ivy.array([[[1, 2],
            [2, 3],
            [3, 4]]])
expand(shape, /, *, copy=None, out=None)[source]#

Broadcast the input Array following the given shape and the broadcast rule.

Parameters:
  • self (Array) – Array input.

  • shape (Union[Shape, NativeShape]) – A 1-D Array indicates the shape you want to expand to, following the broadcast rule

  • copy (Optional[bool], default: None) –

    boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning

    a view of the input array.

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

Return type:

Array

Returns:

ret – Output Array

fill_diagonal(v, /, *, wrap=False)[source]#

ivy.Array instance method variant of ivy.fill_diag.

This method simply wraps the function, and so the docstring for ivy.fill_diag also applies to this method with minimal changes.

Return type:

Array

flatten(*, copy=None, start_dim=0, end_dim=-1, order='C', out=None)[source]#

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

Parameters:
  • self (Array) – input array to flatten.

  • copy (Optional[bool], default: None) –

    boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning a

    view of the input array.

  • start_dim (int, default: 0) – first dim to flatten. If not set, defaults to 0.

  • end_dim (int, default: -1) – last dim to flatten. If not set, defaults to -1.

  • order (str, default: 'C') – Read the elements of the input container using this index order, and place the elements into the reshaped array using this index order. ‘C’ means to read / write the elements using C-like index order, with the last axis index changing fastest, back to the first axis index changing slowest. ‘F’ means to read / write the elements using Fortran-like index order, with the first index changing fastest, and the last index changing slowest. Note that the ‘C’ and ‘F’ options take no account of the memory layout of the underlying array, and only refer to the order of indexing. Default order is ‘C’.

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

Return type:

Array

Returns:

ret – the flattened array over the specified dimensions.

Examples

>>> x = ivy.array([[1,2], [3,4]])
>>> x.flatten()
ivy.array([1, 2, 3, 4])
>>> x = ivy.array([[1,2], [3,4]])
>>> x.flatten(order='F')
ivy.array([1, 3, 2, 4])
>>> x = ivy.array(
    [[[[ 5,  5,  0,  6],
    [17, 15, 11, 16],
    [ 6,  3, 13, 12]],

[[ 6, 18, 10, 4], [ 5, 1, 17, 3], [14, 14, 18, 6]]],

[[[12, 0, 1, 13],

[ 8, 7, 0, 3], [19, 12, 6, 17]],

[[ 4, 15, 6, 15], [ 0, 5, 17, 9], [ 9, 3, 6, 19]]],

[[[17, 13, 11, 16],

[ 4, 18, 17, 4], [10, 10, 9, 1]],

[[19, 17, 13, 10], [ 4, 19, 16, 17], [ 2, 12, 8, 14]]]] )

>>> x.flatten(start_dim = 1, end_dim = 2)
ivy.array(
    [[[ 5,  5,  0,  6],
    [17, 15, 11, 16],
    [ 6,  3, 13, 12],
    [ 6, 18, 10,  4],
    [ 5,  1, 17,  3],
    [14, 14, 18,  6]],

[[12, 0, 1, 13], [ 8, 7, 0, 3], [19, 12, 6, 17], [ 4, 15, 6, 15], [ 0, 5, 17, 9], [ 9, 3, 6, 19]],

[[17, 13, 11, 16], [ 4, 18, 17, 4], [10, 10, 9, 1], [19, 17, 13, 10], [ 4, 19, 16, 17], [ 2, 12, 8, 14]]]))

fliplr(*, copy=None, out=None)[source]#

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

Parameters:
  • self (Array) – The array to be flipped. Must be at least 2-D.

  • copy (Optional[bool], default: None) –

    boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning a

    view of the input array.

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

Return type:

Array

Returns:

ret – Array corresponding to input array with elements order reversed along axis 1.

Examples

>>> m = ivy.diag([1, 2, 3])
>>> m.fliplr()
ivy.array([[0, 0, 1],
       [0, 2, 0],
       [3, 0, 0]])
flipud(*, copy=None, out=None)[source]#

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

Parameters:
  • self (Array) – The array to be flipped.

  • copy (Optional[bool], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning a view of the input array.

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

Return type:

Array

Returns:

ret – Array corresponding to input array with elements order reversed along axis 0.

Examples

>>> m = ivy.diag([1, 2, 3])
>>> m.flipud()
ivy.array([[ 0.,  0.,  3.],
    [ 0.,  2.,  0.],
    [ 1.,  0.,  0.]])
fold(mode, shape, *, out=None)[source]#

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

Parameters:
  • input – unfolded tensor of shape (shape[mode], -1)

  • mode (int) – the mode of the unfolding

  • shape (Union[Shape, NativeShape, Sequence[int]]) – shape of the original tensor before unfolding

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

Return type:

Array

Returns:

ret – folded_tensor of shape shape

heaviside(x2, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • x2 (Array) – values to use where x1 is zero.

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

Return type:

Array

Returns:

ret – output array with element-wise Heaviside step function of x1. This is a scalar if both x1 and x2 are scalars.

Examples

>>> x1 = ivy.array([-1.5, 0, 2.0])
>>> x2 = ivy.array([0.5])
>>> ivy.heaviside(x1, x2)
ivy.array([0.0000, 0.5000, 1.0000])
>>> x1 = ivy.array([-1.5, 0, 2.0])
>>> x2 = ivy.array([1.2, -2.0, 3.5])
>>> ivy.heaviside(x1, x2)
ivy.array([0., -2., 1.])
hsplit(indices_or_sections, /, *, copy=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • indices_or_sections (Union[int, Tuple[int, ...]]) – If indices_or_sections is an integer n, the array is split into n equal sections, provided that n must be a divisor of the split axis. If indices_or_sections is a sequence of ints or 1-D array, then input is split at each of the indices.

  • copy (Optional[bool], default: None) –

    boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning

    a view of the input array.

Return type:

List[Array]

Returns:

ret – list of arrays split horizontally from input array.

Examples

>>> ary = ivy.array(
    [[0.,  1., 2., 3.],
     [4.,  5., 6,  7.],
     [8.,  9., 10., 11.],
     [12., 13., 14., 15.]]
    )
>>> ary.hsplit(2)
[ivy.array([[ 0.,  1.],
            [ 4.,  5.],
            [ 8.,  9.],
            [12., 13.]]),
 ivy.array([[ 2.,  3.],
            [ 6.,  7.],
            [10., 11.],
            [14., 15.]]))
hstack(arrays, /, *, out=None)[source]#

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

Return type:

Array

Examples

>>> x = ivy.array([[1, 2]])
>>> y = [ivy.array([[5, 6]]), ivy.array([[7, 8]])]
>>> print(x.vstack(y))
ivy.array([1, 2, 5, 6, 7, 8])
i0(*, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

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

Return type:

Array

Returns:

ret – Array with modified Bessel function of the first kind, order 0.

Examples

>>> x = ivy.array([[1, 2, 3]])
>>> x.i0()
ivy.array([1.26606588, 2.2795853 , 4.88079259])
matricize(row_modes, column_modes=None, *, out=None)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – the input tensor

  • row_modes (Sequence[int]) – modes to use as row of the matrix (in the desired order)

  • column_modes (Optional[Sequence[int]], default: None) – modes to use as column of the matrix, in the desired order if None, the modes not in row_modes will be used in ascending order

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

  • ret

  • ------- – ivy.Array : tensor of size (ivy.prod(x.shape[i] for i in row_modes), -1)

Return type:

Array

moveaxis(source, destination, /, *, copy=None, out=None)[source]#

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

Parameters:
  • a – The array whose axes should be reordered.

  • source (Union[int, Sequence[int]]) – Original positions of the axes to move. These must be unique.

  • destination (Union[int, Sequence[int]]) – Destination positions for each of the original axes. These must also be unique.

  • copy (Optional[bool], default: None) –

    boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning a view

    of the input array.

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

Return type:

Array

Returns:

ret – Array with moved axes. This array is a view of the input array.

Examples

>>> x = ivy.zeros((3, 4, 5))
>>> x.moveaxis(0, -1).shape
(4, 5, 3)
>>> x.moveaxis(-1, 0).shape
(5, 3, 4)
pad(pad_width, /, *, mode='constant', stat_length=1, constant_values=0, end_values=0, reflect_type='even', out=None, **kwargs)[source]#

ivy.Array instance method variant of ivy.pad.

This method simply wraps the function, and so the docstring for ivy.pad also applies to this method with minimal changes.

Return type:

Array

partial_fold(mode, shape, skip_begin=1, *, out=None)[source]#

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

Parameters:
  • x – a partially unfolded tensor

  • mode (int) – indexing starts at 0, therefore mode is in range(0, tensor.ndim)

  • shape (Union[Shape, NativeShape, Sequence[int]]) – the shape of the original full tensor (including skipped dimensions)

  • skip_begin (Optional[int], default: 1) – number of dimensions left untouched at the beginning

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

Return type:

Array

Returns:

partially re-folded tensor

partial_tensor_to_vec(skip_begin=1, skip_end=0, *, out=None)[source]#

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

Parameters:
  • x – tensor to partially vectorise

  • skip_begin (Optional[int], default: 1) – number of dimensions to leave untouched at the beginning

  • skip_end (Optional[int], default: 0) – number of dimensions to leave untouched at the end

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

Return type:

Array

Returns:

partially vectorised tensor with the skip_begin first and skip_end last dimensions untouched

partial_unfold(mode=0, skip_begin=1, skip_end=0, ravel_tensors=False, *, out=None)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – tensor of shape n_samples x n_1 x n_2 x … x n_i

  • mode (Optional[int], default: 0) – indexing starts at 0, therefore mode is in range(0, tensor.ndim)

  • skip_begin (Optional[int], default: 1) – number of dimensions to leave untouched at the beginning

  • skip_end (Optional[int], default: 0) – number of dimensions to leave untouched at the end

  • ravel_tensors (Optional[bool], default: False) – if True, the unfolded tensors are also flattened

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

Return type:

Array

Returns:

ret – partially unfolded tensor

partial_vec_to_tensor(shape, skip_begin=1, *, out=None)[source]#

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

Parameters:
  • x – a partially vectorised tensor

  • shape (Union[Shape, NativeShape, Sequence[int]]) – the shape of the original full tensor (including skipped dimensions)

  • skip_begin (Optional[int], default: 1) – number of dimensions to leave untouched at the beginning

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

Return type:

Array

Returns:

ret – full tensor

put_along_axis(indices, values, axis, /, *, mode='replace', out=None)[source]#

ivy.Array instance method variant of ivy.put_along_axis.

This method simply wraps the function, and so the docstring for ivy.put_along_axis also applies to this method with minimal changes.

Return type:

Array

rot90(*, copy=None, k=1, axes=(0, 1), out=None)[source]#

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

Parameters:
  • self (Array) – Input array of two or more dimensions.

  • copy (Optional[bool], default: None) –

    boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning

    a view of the input array.

  • k (int, default: 1) – Number of times the array is rotated by 90 degrees.

  • axes (Tuple[int, int], default: (0, 1)) – The array is rotated in the plane defined by the axes. Axes must be different.

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

Return type:

Array

Returns:

ret – Array with a rotated view of input array.

Examples

>>> m = ivy.array([[1,2], [3,4]])
>>> m.rot90()
ivy.array([[2, 4],
       [1, 3]])
>>> m = ivy.array([[1,2], [3,4]])
>>> m.rot90(k=2)
ivy.array([[4, 3],
       [2, 1]])
>>> m = ivy.array([[[0, 1],                            [2, 3]],                           [[4, 5],                            [6, 7]]])
>>> m.rot90(k=2, axes=(1,2))
ivy.array([[[3, 2],
        [1, 0]],
[[7, 6],

[5, 4]]])

soft_thresholding(threshold, *, out=None)[source]#

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

Parameters:
  • x – input array

  • threshold (Union[float, Array, NativeArray]) – float or array with shape tensor.shape * If float the threshold is applied to the whole tensor * If array, one threshold is applied per elements, 0 values are ignored

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

Return type:

Array

Returns:

ivy.Array – thresholded tensor on which the operator has been applied

take(indices, /, *, axis=None, mode='fill', fill_value=None, out=None)[source]#

ivy.Array instance method variant of ivy.take.

This method simply wraps the function, and so the docstring for ivy.take also applies to this method with minimal changes.

Parameters:
  • self (Array) – input array

  • indices (Union[int, Array, NativeArray]) – array indices. Must have an integer data type.

  • axis (Optional[int], default: None) – axis over which to select values. If axis is negative, the function must determine the axis along which to select values by counting from the last dimension. By default, the flattened input array is used.

  • mode (str, default: 'fill') – specifies how out-of-bounds indices will behave. - ‘raise’ – raise an error - ‘wrap’ – wrap around - ‘clip’ – clip to the range (all indices that are too large are replaced by the index that addresses the last element along that axis. Note that this disables indexing with negative numbers.) - ‘fill’ (default) = returns invalid values (e.g. NaN) for out-of bounds indices (see also fill_value below)

  • fill_value (Optional[Number], default: None) – fill value to return for out-of-bounds slices (Defaults to NaN for inexact types, the largest negative value for signed types, the largest positive value for unsigned types, and True for booleans.)

  • 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 having the same data type as x. The output array must have the same rank (i.e., number of dimensions) as x and must have the same shape as x, except for the axis specified by axis whose size must equal the number of elements in indices.

Examples

With ivy.Array input:

>>> x = ivy.array([4,5,6])
>>> indices = ivy.array([2,1,0])
>>> y = x.take(indices)
>>> print(y)
ivy.array([6, 5, 4])
>>> x = ivy.array([4.7,5.2,6.5])
>>> indices = ivy.array([[0,1]])
>>> y = ivy.zeros_like(indices, dtype=x.dtype)
>>> x.take(indices, out=y)
>>> print(y)
ivy.array([[4.7, 5.2]])
>>> x = ivy.array([False, False, True])
>>> indices = ivy.array([[4,3,2]])
>>> y = ivy.zeros_like(indices, dtype=x.dtype)
>>> x.take(indices, out=y, mode="wrap")
>>> print(y)
ivy.array([[False, False, True]])
take_along_axis(indices, axis, /, *, mode='fill', out=None)[source]#

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

Parameters:
  • self (Array) – The source array.

  • indices (Array) – The indices of the values to extract.

  • axis (int) – The axis over which to select values.

  • mode (str, default: 'fill') – One of: ‘clip’, ‘fill’, ‘drop’. Parameter controlling how out-of-bounds indices will be handled.

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

Return type:

Array

Returns:

ret – The returned array has the same shape as indices.

Examples

>>> arr = ivy.array([[4, 3, 5], [1, 2, 1]])
>>> indices = ivy.array([[0, 1, 1], [2, 0, 0]])
>>> y = arr.take_along_axis(indices, 1)
>>> print(y)
ivy.array([[4, 3, 3], [1, 1, 1]])
top_k(k, /, *, axis=-1, largest=True, sorted=True, out=None)[source]#

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

Parameters:
  • self (Array) – The array to compute top_k for.

  • k (int) – Number of top elements to return must not exceed the array size.

  • axis (int, default: -1) – The axis along which we must return the top elements default value is 1.

  • largest (bool, default: True) – If largest is set to False we return k smallest elements of the array.

  • sorted (bool, default: True) – If sorted is set to True we return the elements in sorted order.

  • out (Optional[tuple], default: None) – Optional output tuple, for writing the result to. Must have two arrays, with a shape that the returned tuple broadcast to.

Return type:

Tuple[Array, NativeArray]

Returns:

ret – A named tuple with values and indices of top k elements.

Examples

With ivy.Array input:

>>> x = ivy.array([2., 1., -3., 5., 9., 0., -4])
>>> y = x.top_k(2)
>>> print(y)
top_k(values=ivy.array([9., 5.]), indices=ivy.array([4, 3]))
trim_zeros(*, trim='fb')[source]#

ivy.Array instance method variant of ivy.trim_zeros.

This method simply wraps the function, and so the docstring for ivy.trim_zeros also applies to this method with minimal changes.

Parameters:
  • self (1-D array) – Input array.

  • trim (str, optional) – A string with ‘f’ representing trim from front and ‘b’ to trim from back. Default is ‘fb’, trim zeros from both front and back of the array.

Return type:

Array

Returns:

1-D array The result of trimming the input. The input data type is preserved.

Examples

>>> a = ivy.array([0, 0, 0, 0, 8, 3, 0, 0, 7, 1, 0])
>>> ivy.trim_zeros(a)
array([8, 3, 0, 0, 7, 1])
>>> ivy.trim_zeros(a, 'b')
array([0, 0, 0, 0, 8, 3, 0, 0, 7, 1])
>>> ivy.trim_zeros([0, 8, 3, 0, 0])
[8, 3]
unflatten(shape, dim=0, *, out=None)[source]#

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

Parameters:
  • self (Array) – input array

  • shape (Union[Tuple[int], Array, NativeArray]) – array indices. Must have an integer data type.

  • dim (Optional[int], default: 0) – axis over which to unflatten. If axis is negative, the function must determine the axis along which to select values by counting from the last dimension. By default, the flattened input array is used.

  • 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 having the same data type as x. The output array must have the same rank (i.e., number of dimensions) as x and must have the same shape as x, except for the axis specified by dim which is replaced with a tuple specified in shape.

Examples

With ‘ivy.Array’ input:

>>> x = ivy.array([[1.2, 2.3, 3.4, 4.5],
...               [5.6, 6.7, 7.8, 8.9]])
>>> dim = 1
>>> shape = (2, 2)
>>> y = ivy.zeros([2, 2, 2])
>>> x.unflatten(shape=shape, dim=dim, out=y)
>>> print(y)
ivy.array([[[1.2, 2.3], [3.4, 4.5]], [[5.6, 6.7], [7.8, 8.9]]])
unfold(mode=0, *, out=None)[source]#

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

Parameters:
  • self (Union[Array, NativeArray]) – input tensor to be unfolded

  • mode (Optional[int], default: 0) – indexing starts at 0, therefore mode is in range(0, tensor.ndim)

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

Return type:

Array

Returns:

ret – unfolded_tensor of shape (tensor.shape[mode], -1)

unique_consecutive(*, axis=None)[source]#

ivy.Array instance method variant of ivy.unique_consecutive.

This method simply wraps the function, and so the docstring for ivy.unique_consecutive also applies to this method with minimal changes.

Return type:

Tuple[Array, Array, Array]

vsplit(indices_or_sections, /, *, copy=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • copy (Optional[bool], default: None) –

    boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning

    a view of the input array.

  • indices_or_sections (Union[int, Sequence[int], Array]) – If indices_or_sections is an integer n, the array is split into n equal sections, provided that n must be a divisor of the split axis. If indices_or_sections is a sequence of ints or 1-D array, then input is split at each of the indices.

Return type:

List[Array]

Returns:

ret – input array split vertically.

Examples

>>> ary = ivy.array(
    [[[0.,  1.],
      [2.,  3.]],
     [[4.,  5.],
      [6.,  7.]]]
    )
>>> ary.vsplit(2)
[ivy.array([[[0., 1.], [2., 3.]]]), ivy.array([[[4., 5.], [6., 7.]]])])
vstack(arrays, /, *, out=None)[source]#

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

Return type:

Array

Examples

>>> x = ivy.array([[1, 2]])
>>> y = [ivy.array([[5, 6]]), ivy.array([[7, 8]])]
>>> print(x.vstack(y))
    ivy.array([[1, 2],
               [5, 6],
               [7, 8]])
class ivy.data_classes.array.experimental.norms._ArrayWithNormsExperimental[source]#
_abc_impl = <_abc._abc_data object>#
batch_norm(mean, variance, /, *, offset=None, scale=None, training=False, eps=1e-05, momentum=0.1, data_format='NSC', out=None)[source]#

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

Parameters:
  • self (Union[NativeArray, Array]) –

    Input array of default shape (N, *S, C), where N is the batch dimension, *S corresponds to any number of spatial dimensions and

    C corresponds to the channel dimension.

  • training (bool, default: False) – If true, calculate and use the mean and variance of x. Otherwise, use the provided mean and variance.

  • mean (Optional[Union[Array, NativeArray]]) – Mean array used for input’s normalization. It can be of any shape braodcastable to (N,*S,C).

  • variance (Optional[Union[Array, NativeArray]]) – Variance array used for input’s normalization. It can be of any shape braodcastable to (N,*S,C).

  • offset (Optional[Union[Array, NativeArray]], default: None) – An offset array. If present, will be added to the normalized input. It can be of any shape broadcastable to (N,*S,C).

  • scale (Optional[Union[Array, NativeArray]], default: None) – A scale array. If present, the scale is applied to the normalized input. It can be of any shape broadcastable to (N,*S,C).

  • eps (float, default: 1e-05) – A small float number to avoid dividing by 0.

  • momentum (float, default: 0.1) –

    the value used for the running_mean and running_var computation.

    Default value is 0.1.

  • data_format (str, default: 'NSC') – The ordering of the dimensions in the input, one of “NSC” or “NCS”, where N is the batch dimension, S represents any number of spatial dimensions and C is the channel dimension. Default is “NSC”.

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

Return type:

Tuple[Array, Array, Array]

Returns:

ret – Tuple of arrays containing the normalized input, running mean, and running variance.

group_norm(num_groups=1, /, *, offset=None, scale=None, eps=1e-05, data_format='NSC', out=None)[source]#

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

Parameters:
  • x – Input array of default shape (N, *S, C), where N is the batch dimension, *S corresponds to any number of spatial dimensions and C corresponds to the channel dimension.

  • num_groups (int, default: 1) – number of groups to separate the channels into

  • offset (Optional[Union[Array, NativeArray]], default: None) – An offset array of size C. If present, will be added to the normalized input.

  • scale (Optional[Union[Array, NativeArray]], default: None) – A scale array of size C. If present, the scale is applied to the normalized input.

  • eps (Optional[float], default: 1e-05) – A small float number to avoid dividing by 0.

  • data_format (Optional[str], default: 'NSC') – The ordering of the dimensions in the input, one of “NSC” or “NCS”, where N is the batch dimension, S represents any number of spatial dimensions and C is the channel dimension. Default is “NSC”.

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

Return type:

Array

Returns:

ret – The normalized array.

instance_norm(mean, variance, /, *, offset=None, scale=None, training=False, eps=1e-05, momentum=0.1, data_format='NSC', out=None)[source]#

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

Parameters:
  • self (Union[NativeArray, Array]) –

    Input array of shape default (N, *S, C), where N is the batch dimension, *S corresponds to any number of spatial dimensions and

    C corresponds to the channel dimension.

  • mean (Optional[Union[Array, NativeArray]]) – Mean array of size C used for input’s normalization.

  • variance (Optional[Union[Array, NativeArray]]) – Variance array of size C used for input’s normalization.

  • offset (Optional[Union[Array, NativeArray]], default: None) – An offset array of size C. If present, will be added to the normalized input.

  • scale (Optional[Union[Array, NativeArray]], default: None) – A scale array of size C. If present, the scale is applied to the normalized input.

  • training (bool, default: False) – If true, calculate and use the mean and variance of x. Otherwise, use the provided mean and variance.

  • eps (float, default: 1e-05) – A small float number to avoid dividing by 0.

  • momentum (float, default: 0.1) –

    the value used for the running_mean and running_var computation.

    Default value is 0.1.

  • data_format (str, default: 'NSC') – The ordering of the dimensions in the input, one of “NSC” or “NCS”, where N is the batch dimension, S represents any number of spatial dimensions and C is the channel dimension. Default is “NSC”.

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

Return type:

Tuple[Array, Array, Array]

Returns:

ret

Tuple of array containing

the normalized input, running mean, and running variance.

l1_normalize(axis=None, out=None)[source]#

Normalize the array to have unit L1 norm.

Parameters:
  • self (Array) – Input array.

  • axis (Optional[Union[int, Tuple[int, ...]]], default: None) – Axis or axes along which to normalize. If None, the whole array is normalized.

  • 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 – The normalized array.

Examples

>>> x = ivy.array([[1., 2.], [3., 4.]])
>>> y = x.l1_normalize(axis=1)
>>> print(y)
ivy.array([[0.33333334, 1.33333337],
       [1.28571439, 2.28571439]])
l2_normalize(axis=None, out=None)[source]#

Normalize the array to have unit L2 norm.

Parameters:
  • self (Array) – Input array.

  • axis (Optional[int], default: None) – Axis along which to normalize. If None, the whole array is normalized.

  • 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 – The normalized array.

Examples

>>> x = ivy.array([[1., 2.], [3., 4.]])
>>> y = x.l2_normalize(axis=1)
>>> print(y)
ivy.array([[0.44721359, 0.89442718],
       [0.60000002, 0.80000001]])
lp_normalize(*, p=2, axis=None, out=None)[source]#

Normalize the array to have Lp norm.

Parameters:
  • self (Array) – Input array.

  • p (float, default: 2) – p-norm to use for normalization.

  • axis (Optional[int], default: None) – Axis along which to normalize. If None, the whole array is normalized.

  • 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 – The normalized array.

Examples

>>> x = ivy.array([[1., 2.], [3., 4.]])
>>> y = x.lp_normalize(p=2, axis=1)
>>> print(y)
ivy.array([[0.44721359, 0.89442718],
       [0.60000002, 0.80000001]])
class ivy.data_classes.array.experimental.random._ArrayWithRandomExperimental[source]#
_abc_impl = <_abc._abc_data object>#
bernoulli(*, logits=None, shape=None, device=None, dtype=None, seed=None, out=None)[source]#
Parameters:
  • self (Array) – An N-D Array representing the probability of a 1 event. Each entry in the Array parameterizes an independent Bernoulli distribution. Only one of logits or probs should be passed in

  • logits (Optional[Union[float, Array, NativeArray]], default: None) – An N-D Array representing the log-odds of a 1 event. Each entry in the Array parameterizes an independent Bernoulli distribution where the probability of an event is sigmoid (logits). Only one of logits or probs should be passed in.

  • shape (Optional[Union[Shape, NativeShape]], default: None) – If the given shape is, e.g ‘(m, n, k)’, then ‘m * n * k’ samples are drawn. (Default value = ‘None’, where ‘ivy.shape(logits)’ samples are drawn)

  • device (Optional[Union[Device, NativeDevice]], default: None) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None).

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – output array data type. If dtype is None, the output array data type will be the default floating-point data type. Default None

  • seed (Optional[int], default: None) – A python integer. Used to create a random seed distribution

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

Returns:

ret – Drawn samples from the Bernoulli distribution

beta(beta, /, *, shape=None, device=None, dtype=None, seed=None, out=None)[source]#

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

Parameters:
  • self (Array) – Input Array.

  • alpha – The first parameter of the beta distribution.

  • beta (Union[int, Array, NativeArray]) – The second parameter of the beta distribution.

  • device (Optional[Union[Device, NativeDevice]], default: None) – device on which to create the array.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – output array data type. If dtype is None, the output array data type will be the default data type. Default None

  • seed (Optional[int], default: None) – A python integer. Used to create a random seed distribution

  • 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 – Drawn samples from the parameterized beta distribution with the shape of the array.

dirichlet(*, size=None, dtype=None, seed=None, out=None)[source]#

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

Parameters:
  • self (Array) – Sequence of floats of length k

  • size (Optional[Union[Shape, NativeShape]], default: None) – optional int or tuple of ints, Output shape. If the given shape is, e.g., (m, n), then m * n * k samples are drawn. Default is None, in which case a vector of length k is returned.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – output array data type. If dtype is None, the output array data type will be the default floating-point data type. Default None

  • seed (Optional[int], default: None) – A python integer. Used to create a random seed distribution

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

Return type:

Array

Returns:

ret – The drawn samples, of shape (size, k).

Examples

>>> alpha = ivy.array([1.0, 2.0, 3.0])
>>> alpha.dirichlet()
ivy.array([0.10598304, 0.21537054, 0.67864642])
>>> alpha = ivy.array([1.0, 2.0, 3.0])
>>> alpha.dirichlet(size = (2,3))
ivy.array([[[0.48006698, 0.07472073, 0.44521229],
    [0.55479872, 0.05426367, 0.39093761],
    [0.19531053, 0.51675832, 0.28793114]],
[[0.12315625, 0.29823365, 0.5786101 ],

[0.15564976, 0.50542368, 0.33892656], [0.1325352 , 0.44439589, 0.42306891]]])

gamma(beta, /, *, shape=None, device=None, dtype=None, seed=None, out=None)[source]#

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

Parameters:
  • self (Array) – Input Array and the first parameter of the gamma distribution.

  • beta (Union[int, Array, NativeArray]) – The second parameter of the gamma distribution.

  • shape (Optional[Union[Shape, NativeShape]], default: None) – If the given shape is, e.g ‘(m, n, k)’, then ‘m * n * k’ samples are drawn. (Default value = ‘None’, where ‘ivy.shape(logits)’ samples are drawn)

  • device (Optional[Union[Device, NativeDevice]], default: None) – device on which to create the array.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – output array data type. If dtype is None, the output array data type will be the default data type. Default None

  • seed (Optional[int], default: None) – A python integer. Used to create a random seed distribution

  • 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 – Drawn samples from the parameterized gamma distribution with the shape of the input array.

poisson(*, shape=None, device=None, dtype=None, seed=None, fill_value=0, out=None)[source]#
Parameters:
  • self (Array) – Input Array of rate parameter(s). It must have a shape that is broadcastable to the requested shape

  • shape (Optional[Union[Shape, NativeShape]], default: None) – If the given shape is, e.g ‘(m, n, k)’, then ‘m * n * k’ samples are drawn. (Default value = ‘None’, where ‘ivy.shape(lam)’ samples are drawn)

  • device (Optional[Union[Device, NativeDevice]], default: None) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None).

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – output array data type. If dtype is None, the output array data type will be the default floating-point data type. Default None

  • seed (Optional[int], default: None) – A python integer. Used to create a random seed distribution

  • fill_value (Optional[Union[float, int]], default: 0) – if lam is negative, fill the output array with this value on that specific dimension.

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

Returns:

ret – Drawn samples from the parameterized poisson distribution.

Examples

>>> lam = ivy.array([1.0, 2.0, 3.0])
>>> lam.poisson()
ivy.array([1., 4., 4.])
>>> lam = ivy.array([1.0, 2.0, 3.0])
>>> lam.poisson(shape=(2,3))
ivy.array([[0., 2., 2.],
           [1., 2., 3.]])
class ivy.data_classes.array.experimental.searching._ArrayWithSearchingExperimental[source]#
_abc_impl = <_abc._abc_data object>#
unravel_index(shape, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • shape (Tuple[int]) – The shape of the array to use for unraveling indices.

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

Return type:

Tuple[Array]

Returns:

ret – Tuple with arrays that have the same shape as the indices array.

Examples

>>> indices = ivy.array([22, 41, 37])
>>> indices.unravel_index((7,6))
(ivy.array([3, 6, 6]), ivy.array([4, 5, 1]))
class ivy.data_classes.array.experimental.set._ArrayWithSetExperimental[source]#
_abc_impl = <_abc._abc_data object>#
class ivy.data_classes.array.experimental.sorting._ArrayWithSortingExperimental[source]#
_abc_impl = <_abc._abc_data object>#
lexsort(*, axis=-1, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • axis (int, default: -1) – axis of each key to be indirectly sorted. By default, sort over the last axis of each key.

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

Return type:

Array

Returns:

ret – array of integer indices with shape N, that sort the input array as keys.

Examples

>>> a = [1,5,1,4,3,4,4] # First column
>>> b = [9,4,0,4,0,2,1] # Second column
>>> keys = ivy.asarray([b,a])
>>> keys.lexsort() # Sort by a, then by b
array([2, 0, 4, 6, 5, 3, 1])
class ivy.data_classes.array.experimental.statistical._ArrayWithStatisticalExperimental[source]#
_abc_impl = <_abc._abc_data object>#
bincount(*, weights=None, minlength=0, out=None)[source]#

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

Parameters:
  • self – Input array. The array is flattened if it is not already 1-dimensional.

  • weights (Optional[Array], default: None) – Optional weights, array of the same shape as self.

  • minlength (int, default: 0) – A minimum number of bins for the output array.

  • out (Optional[Array], default: None) – An array of the same shape as the returned array, or of the shape (minlength,) if minlength is specified.

Return type:

Array

Returns:

ret – The result of binning the input array.

Examples

>>> a = ivy.array([0, 1, 1, 3, 2, 1, 7])
>>> a.bincount()
    ivy.array([1, 3, 1, 1, 0, 0, 0, 1])
>>> a.bincount(minlength=10)
    ivy.array([1, 3, 1, 1, 0, 0, 0, 1, 0, 0])
>>> a.bincount(weights=ivy.array([0.3, 0.5, 0.2, 0.7, 1., 0.6, 1.]))
    ivy.array([0.3, 1.3, 1. , 0.7, 0. , 0. , 0. , 1. ])
corrcoef(*, y=None, rowvar=True, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • y (Optional[Array], default: None) – An additional input array. y has the same shape as x.

  • rowvar (bool, default: True) – If rowvar is True (default), then each row represents a variable, with observations in the columns. Otherwise, the relationship is transposed: each column represents a variable, while the rows contain observations.

Return type:

Array

Returns:

ret – The corrcoef of the array elements.

Examples

>>> a = ivy.array([[0., 1., 2.], [2., 1., 0.]])
>>> a.corrcoef()
    ivy.array([[ 1., -1.],
               [-1.,  1.]])
>>> a.corrcoef(rowvar=False)
    ivy.array([[ 1., nan, -1.],
               [nan, nan, nan],
               [-1., nan,  1.]])
cov(x2=None, /, *, rowVar=True, bias=False, ddof=None, fweights=None, aweights=None, dtype=None)[source]#

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

Parameters:
  • self (Array) – a 1D or 2D input array, with a numeric data type.

  • x2 (Optional[Union[Array, NativeArray]], default: None) – optional second 1D or 2D input array, with a numeric data type. Must have the same shape as self.

  • rowVar (bool, default: True) – optional variable where each row of input is interpreted as a variable (default = True). If set to False, each column is instead interpreted as a variable.

  • bias (bool, default: False) – optional variable for normalizing input (default = False) by (N - 1) where N is the number of given observations. If set to True, then normalization is instead by N. Can be overridden by keyword ddof.

  • ddof (Optional[int], default: None) – optional variable to override bias (default = None). ddof=1 will return the unbiased estimate, even with fweights and aweights given. ddof=0 will return the simple average.

  • fweights (Optional[Array], default: None) – optional 1D array of integer frequency weights; the number of times each observation vector should be repeated.

  • aweights (Optional[Array], default: None) – optional 1D array of observation vector weights. These relative weights are typically large for observations considered “important” and smaller for observations considered less “important”. If ddof=0 is specified, the array of weights can be used to assign probabilities to observation vectors.

  • dtype (Optional[type], default: None) – optional variable to set data-type of the result. By default, data-type will have at least float64 precision.

  • out – 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 containing the covariance matrix of an input matrix, or the covariance matrix of two variables. The returned array must have a floating-point data type determined by Type Promotion Rules and must be a square matrix of shape (N, N), where N is the number of variables in the input(s).

Examples

>>> x = ivy.array([[1, 2, 3],
...                [4, 5, 6]])
>>> y = x[0].cov(x[1])
>>> print(y)
ivy.array([[1., 1.],
       [1., 1.]])
>>> x = ivy.array([1,2,3])
>>> y = ivy.array([4,5,6])
>>> z = x.cov(y)
>>> print(z)
ivy.array([[1., 1.],
       [1., 1.]])
cummax(*, axis=0, exclusive=False, reverse=False, dtype=None, out=None)[source]#

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

Parameters:
  • self (Array) – input array

  • axis (int, default: 0) – int, axis along which to take the cumulative maximum. Default is 0.

  • reverse (bool, default: False) – Whether to perform the cummax from last to first element in the selected axis. Default is False (from first to last element)

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – data type of the returned array. If None, if the default data type corresponding to the data type “kind” (integer or floating-point) of x has a smaller range of values than the data type of x (e.g., x has data type int64 and the default data type is int32, or x has data type uint64 and the default data type is int64), the returned array must have the same data type as x. if x has a floating-point data type, the returned array must have the default floating-point data type. if x has a signed integer data type (e.g., int16), the returned array must have the default integer data type. if x has an unsigned integer data type (e.g., uint16), the returned array must have an unsigned integer data type having the same number of bits as the default integer data type (e.g., if the default integer data type is int32, the returned array must have a uint32 data type). If the data type (either specified or resolved) differs from the data type of x, the input array should be cast to the specified data type before computing the product. Default: None.

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

Return type:

Array

Returns:

  • ret – Input array with cumulatively multiplied elements along the specified axis.

  • ——–

  • >>> x = ivy.array([1, 2, 5, 4, 3])

  • >>> y = x.cummax()

  • >>> print(y)

  • (ivy.array([1, 2, 5, 5, 5]), ivy.array([0, 1, 2, 2, 2]))

  • >>> x = ivy.array([[2, 3], [5, 7], [11, 13]])

  • >>> y = ivy.zeros((3, 2), dtype=”int32”)

  • >>> x.cummax(axis=1, reverse=True, out=y)

  • >>> print(y)

  • ivy.array([[0, 0], – [0, 0], [0, 0]])

cummin(*, axis=0, exclusive=False, reverse=False, dtype=None, out=None)[source]#

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

Parameters:
  • self (Array) – input array

  • axis (int, default: 0) – int, axis along which to take the cumulative minimum. Default is 0.

  • reverse (bool, default: False) – Whether to perform the cummin from last to first element in the selected axis. Default is False (from first to last element)

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – data type of the returned array. If None, if the default data type corresponding to the data type “kind” (integer or floating-point) of x has a smaller range of values than the data type of x (e.g., x has data type int64 and the default data type is int32, or x has data type uint64 and the default data type is int64), the returned array must have the same data type as x. if x has a floating-point data type, the returned array must have the default floating-point data type. if x has a signed integer data type (e.g., int16), the returned array must have the default integer data type. if x has an unsigned integer data type (e.g., uint16), the returned array must have an unsigned integer data type having the same number of bits as the default integer data type (e.g., if the default integer data type is int32, the returned array must have a uint32 data type). If the data type (either specified or resolved) differs from the data type of x, the input array should be cast to the specified data type before computing the product. Default: None.

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

Return type:

Array

Returns:

  • ret – Input array with cumulatively multiplied elements along the specified axis.

  • ——–

  • >>> x = ivy.array([1, 2, 3, 4, 5])

  • >>> y = x.cummin()

  • >>> print(y)

  • ivy.array([1, 1, 1, 1, 1])

  • >>> x = ivy.array([[2, 3], [5, 7], [11, 13]])

  • >>> y = ivy.zeros((3, 2), dtype=”int32”)

  • >>> x.cummin(axis=1, reverse=True, out=y)

  • >>> print(y)

  • ivy.array([[ 2, 3], – [ 5, 7], [11, 13]])

histogram(*, bins=None, axis=None, extend_lower_interval=False, extend_upper_interval=False, dtype=None, range=None, weights=None, density=False, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • bins (Optional[Union[int, Array, NativeArray, str]], default: None) – if bins is an int, it defines the number of equal-width bins in the given range. if bins is an array, it defines a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform bin widths.

  • axis (Optional[Union[Array, NativeArray]], default: None) – dimension along which maximum values must be computed. By default, the maximum value must be computed over the entire array. Default: None.

  • extend_lower_interval (Optional[bool], default: False) – if True, extend the lowest interval I0 to (-inf, c1].

  • extend_upper_interval (Optional[bool], default: False) – ff True, extend the upper interval I_{K-1} to [c_{K-1}, +inf).

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – the output type.

  • range (Optional[Tuple[float]], default: None) – the lower and upper range of the bins. The first element of the range must be less than or equal to the second.

  • weights (Optional[Union[Array, NativeArray]], default: None) – each value in a only contributes its associated weight towards the bin count (instead of 1). Must be of the same shape as a.

  • density (Optional[bool], default: False) – if True, the result is the value of the probability density function at the bin, normalized such that the integral over the range of bins is 1.

  • 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 – a tuple containing the values of the histogram and the bin edges.

  • Both the description and the type hints above assumes an array input for

  • simplicity, but this function is *nestable, and therefore also accepts*

  • ivy.Container instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> x = ivy.array([0, 1, 2])
>>> y = ivy.array([0., 0.5, 1., 1.5, 2.])
>>> z = ivy.histogram(x, bins=y)
>>> print(z)
ivy.array([1., 0., 1., 1.])
igamma(*, x, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • x (Union[Array, NativeArray]) – An additional input array. x has the same type as a.

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

Return type:

Array

Returns:

ret – The lower incomplete gamma function of the array elements.

Examples

>>> a = ivy.array([2.5])
>>> x = ivy.array([1.7, 1.2])
>>> a.igamma(x)
    ivy.array([0.3614, 0.2085])
median(*, axis=None, keepdims=False, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • axis (Optional[Union[int, Tuple[int]]], default: None) – Axis or axes along which the medians are computed. The default is to compute the median along a flattened version of the array.

  • keepdims (bool, default: False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one.

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

Return type:

Array

Returns:

ret – The median of the array elements.

Examples

>>> a = ivy.array([[10, 7, 4], [3, 2, 1]])
>>> a.median()
3.5
>>> a.median(axis=0)
ivy.array([6.5, 4.5, 2.5])
nanmean(*, axis=None, keepdims=False, dtype=None, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • axis (Optional[Union[int, Tuple[int]]], default: None) – Axis or axes along which the means are computed. The default is to compute the mean of the flattened array.

  • keepdims (bool, default: False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a. If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – The desired data type of returned tensor. Default is None.

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

Return type:

Array

Returns:

ret – The nanmean of the array elements.

Examples

>>> a = ivy.array([[1, ivy.nan], [3, 4]])
>>> a.nanmean()
2.6666666666666665
>>> a.nanmean(axis=0)
ivy.array([2.,  4.])
nanmedian(*, axis=None, keepdims=False, overwrite_input=False, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • axis (Optional[Union[int, Tuple[int]]], default: None) – The axis or axes along which the means are computed. The default is to compute the mean of the flattened array.

  • keepdims (bool, default: False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original input array. If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.

  • overwrite_input (bool, default: False) – If True, then allow use of memory of input array a for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array. Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. If overwrite_input is True and input array is not already an ndarray, an error will be raised.

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

Return type:

Array

Returns:

ret – A new array holding the result. If the input contains integers

Examples

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

>>> a = ivy.array([[10.0, ivy.nan, 4], [3, 2, 1]])
>>> a.nanmedian()
    ivy.array(3.)
>>> a.nanmedian(axis=0)
    ivy.array([6.5, 2. , 2.5])
nanmin(*, axis=None, keepdims=False, initial=None, where=None, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • axis (Optional[Union[int, Tuple[int]]], default: None) – Axis or axes along which the minimum is computed. The default is to compute the minimum of the flattened array.

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

  • keepdims (Optional[bool], default: False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.

  • initial (Optional[Union[int, float, complex]], default: