General¶
Collection of general Ivy functions.

ivy.
abs
(x, f=None)[source]¶ Returns the absolute value of each element in x.
 Parameters
x (array) – Input array containing elements to absolute value.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
A new array of the same shape as input array a, with all values now positive.

ivy.
arange
(stop, start=0, step=1, dtype_str=None, dev_str=None, f=None)[source]¶ Returns evenly spaced values within a given interval, with the spacing being specified.
Values are generated within the halfopen interval [start, stop) (in other words, the interval including start but excluding stop). For integer arguments the function is equivalent to the Python builtin range function, but returns an array in the chosen ml_framework rather than a list.
See \(linspace\) for a certain number of evenly spaced values in an interval.
 Parameters
stop (number) – End of interval. The interval does not include this value, except in some cases where step is not an integer and floating point roundoff affects the length of out.
start (number, optional) – Start of interval. The interval includes this value. The default start value is 0.
step (number, optional) – Spacing between values. For any output out, this is the distance between two adjacent values, out[i+1]  out[i]. The default step size is 1. If step is specified as a position argument, start must also be given.
dtype_str (datatype string, optional) – The desired datatype for the array in string format, i.e. ‘float32’ or ‘int64’. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence.
dev_str (str) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Tensor of evenly spaced values.
For floating point arguments, the length of the result is ceil((stop  start)/step). Because of floating point overflow, this rule may result in the last element of out being greater than stop.

ivy.
argmax
(x, axis=0, f=None)[source]¶ Returns the index with the largest value across axes of an array.
 Parameters
x (array) – Input array containing elements to argmax.
axis (int, optional) – Axis to perform the argmax, default is 0.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Tensor containing the indices of the maximum values across the specified axis.

ivy.
argmin
(x, axis=0, f=None)[source]¶ Returns the index with the smallest value across axes of an array.
 Parameters
x (array) – Input array containing elements to argmin.
axis (int, optional) – Axis to perform the argmin, default is 0.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Tensor containing the indices of the minimum values across the specified axis.

ivy.
argsort
(x, axis= 1, f=None)[source]¶ Returns the indices of a tensor that give its sorted order along an axis.
 Parameters
x (array) – Input array containing elements to argsort.
axis (int, optional) – Axis to perform the argsort, default is 1.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
The indices that would sort each slice of the given values along the given axis.

ivy.
array
(object_in, dtype_str=None, dev_str=None, f=None)[source]¶ Creates an array.
 Parameters
object_in (array) – An array_like object, which exposes the array interface, an object whose __array__ method returns an array, or any (nested) sequence.
dtype_str (datatype string, optional) – The desired datatype for the array in string format, i.e. ‘float32’ or ‘int64’. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence.
dev_str (str) – device string on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc..
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
An array object satisfying the specified requirements, in the form of the selected framework.

ivy.
broadcast_to
(x, newshape, f=None)[source]¶ Broadcast the input tensor to newshape, adding dimensions of size 1 where the dimensions do not align.
 Parameters
x (array) – Tensor to be broadcast to new shape.
newshape (sequence of ints) – The new shape the tensor should be broadcast to.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Newly broadcast array.

ivy.
cast
(x, dtype_str, f=None)[source]¶ Casts an array to a specified type.
 Parameters
x (array) – Input array containing elements to cast.
dtype_str (datatype string) – The desired datatype for the array in string format, i.e. ‘float32’ or ‘int64’. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
A new array of the same shape as input array a, with data type given by dtype_str.

ivy.
ceil
(x, f=None)[source]¶ Returns elementwise smallest integer not less than x.
 Parameters
x (array) – Input array to ceil.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
An array of the same shape and type as x, with the elements ceiled to integers.

ivy.
clip
(x, x_min, x_max, f=None)[source]¶ Clips (limits) the values in an array.
Given an interval, values outside the interval are clipped to the interval edges (elementwise). For example, if an interval of [0, 1] is specified, values smaller than 0 become 0, and values larger than 1 become 1.
 Parameters
x (array) – Input array containing elements to clip.
x_min (scalar) – Minimum value.
x_max (scalar) – Maximum value.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
An array with the elements of x, but where values < x_min are replaced with x_min, and those > x_max with x_max.

ivy.
compile_fn
(func, dynamic=True, example_inputs=None, f=None)[source]¶ Provide a function which should be compiled, for faster inference. The handle to the newly compiled function is returned.
 Parameters
func (function) – Function to be compiled.
dynamic (bool, default True) – Whether to compile all conditional branches, regardless of inputs during first invocation.
example_inputs (single input of tuple of inputs.) – Example of inputs to the function to be compiled. Required for torch in nondynamic mode, unused by other frameworks.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
The handle to the newly compiled function.

ivy.
concatenate
(xs, axis= 1, f=None)[source]¶ Casts an array to a specified type.
 Parameters
xs (sequence of arrays) – The input arrays must have the same shape, except in the dimension corresponding to axis (the first, by default).
axis (int, optional) – The axis along which the arrays will be joined. Default is 1.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
The concatenated array.

ivy.
constant_pad
(x, pad_width, value=0, f=None)[source]¶ Pads an array with a constant value.
 Parameters
x (array) – Input array to pad.
pad_width (sequence of tuples of ints) – Number of values padded to the edges of each axis. Specified as ((before_1, after_1), … (before_N, after_N)), where N is number of axes of x.
value (float or int, default zero) – The constant value to pad the array with.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Padded array of rank equal to x with shape increased according to pad_width.

ivy.
cross
(x1, x2, f=None)[source]¶ Returns the cross product of two (arrays of) vectors in R^3. The cross product of x1 and x2 in R^3 is a vector perpendicular to both x1 and x2. If x1 and x2 are arrays of vectors, the vectors are defined by the last axis of x1 and x2 by default which must have dimension 3.
 Parameters
x1 (array) – Components of the first vector(s).
x2 (array) – Components of the second vector(s).
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Vector cross product(s).

ivy.
cumprod
(x, axis=0, exclusive=False, f=None)[source]¶ Returns the cumulative product of the elements along a given axis.
 Parameters
x (array) – Input array.
axis (int) – Axis along which the cumulative product is computed. By default 0.
exclusive (bool, optional) – Whether to perform the cumprod exclusively. Defaults is False.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Input array with cumulatively multiplied elements along axis.

ivy.
cumsum
(x, axis=0, f=None)[source]¶ Returns the cumulative sum of the elements along a given axis.
 Parameters
x (array) – Input array.
axis (int) – Axis along which the cumulative sum is computed. By default 0.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Input array with cumulatively summed elements along axis.

ivy.
dev
(x, f=None)[source]¶ Get the native device handle for input array x.
 Parameters
x (array) – Tensor for which to get the device handle.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Device handle for the array, in native framework format.

ivy.
dev_str
(x, f=None)[source]¶ Get the device string for input array x.
 Parameters
x (array) – Tensor for which to get the device string.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Device string for the array, e.g. ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc..

ivy.
dev_to_str
(dev_in, f=None)[source]¶ Convert native data type to string representation.
 Parameters
dev_in (device handle) – The device handle to convert to string.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Device string e.g. ‘cuda:0’.

ivy.
dtype
(x, f=None)[source]¶ Get the data type for input array x.
 Parameters
x (array) – Tensor for which to get the data type.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Data type of the array

ivy.
dtype_str
(x, f=None)[source]¶ Get the data type string for input array x.
 Parameters
x (array) – Tensor for which to get the data type string.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Device string e.g. ‘float32’.

ivy.
dtype_to_str
(dtype_in, f=None)[source]¶ Convert native data type to string representation.
 Parameters
dtype_in (data type) – The data type to convert to string.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Device string e.g. ‘float32’.

ivy.
expand_dims
(x, axis, f=None)[source]¶ Expands the shape of an array. Inserts a new axis that will appear at the axis position in the expanded array shape.
 Parameters
x (array) – Input array.
axis (int) – Position in the expanded axes where the new axis is placed.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
array with the number of dimensions increased by onearray

ivy.
flip
(x, axis=None, batch_shape=None, f=None)[source]¶ Reverses the ord of elements in an array along the given axis. The shape of the array is preserved, but the elements are reordered.
 Parameters
x (array) – Input array.
axis (None or int or sequence of ints, optional) – Axis or axes along which to flip over. The default, axis=None, will flip over all axes.
batch_shape (sequence of ints, optional) – Shape of batch. Inferred from inputs if None.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
An array with the entries of axis reversed.

ivy.
floor
(x, f=None)[source]¶ Returns elementwise largest integer not greater than x.
 Parameters
x (array) – Input array to floor.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
An array of the same shape and type as x, with the elements floored to integers.

ivy.
floormod
(x, y, f=None)[source]¶ Returns elementwise remainder of division.
 Parameters
x (array) – Input array to floormod.
y (array) – Denominator input for floormod.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
An array of the same shape and type as x, with the elements floor modded.

ivy.
gather
(params, indices, axis= 1, dev_str=None, f=None)[source]¶ Gather slices from params axis axis according to indices.
 Parameters
params (array) – The array from which to gather values.
indices (array) – Index array.
axis (int, optional) – The axis from which to gather from. Default is 1.
dev_str (str, optional) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Same as x if None.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
New array with the values gathered at the specified indices along the specified axis.

ivy.
gather_nd
(params, indices, dev_str=None, f=None)[source]¶ Gather slices from params into a array with shape specified by indices.
 Parameters
params (array) – The array from which to gather values.
indices (array) – Index array.
dev_str (str, optional) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Same as x if None.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
New array of given shape, with the values gathered at the indices.

ivy.
get_num_dims
(x, as_array=False, f=None)[source]¶ Returns the number of dimensions of the array x.
 Parameters
x (array) – Input array to infer the number of dimensions for.
as_array (bool, optional) – Whether to return the shape as a array, default False.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Shape of the array

ivy.
gpu_is_available
(f=None)[source]¶ Determine whether a GPU is available to use, with the backend framework.
 Parameters
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Boolean, as to whether a gpu is available.

ivy.
identity
(n, dtype_str='float32', batch_shape=None, dev_str=None, f=None)[source]¶ Returns the identity array. The identity array is a square array with ones on the main diagonal.
 Parameters
n (int) – Number of rows (and columns) in n x n output.
dtype_str (datatype string, optional) – The desired datatype for the array in string format, i.e. ‘float32’ or ‘int64’. Default is ‘float32’.
batch_shape (sequence of ints, optional) – Shape of batch. Inferred from inputs if None.
dev_str (str) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc..
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
n x n array of type dtype_str, with its main diagonal set to one, and all other elements 0.

ivy.
indices_where
(x, f=None)[source]¶ Returns indices or true elements in an input boolean array.
 Parameters
x (array) – Boolean array, for which indices are desired.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Indices for where the boolean array is True.

ivy.
is_array
(x, f=None)[source]¶ Determines whether the input x is an Ivy Array.
 Parameters
x (any) – The input to check
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Boolean, whether or not x is an array.

ivy.
isnan
(x, f=None)[source]¶ Returns boolean map at locations where the input is not a number (nan).
 Parameters
x (array) – Input array.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Boolean values for where the values of the array are nan.

ivy.
linspace
(start, stop, num, axis=None, dev_str=None, f=None)[source]¶ Generates a certain number of evenlyspaced values in an interval along a given axis.
See \(arange\) that allows to specify the step size of evenly spaced values in an interval.
 Parameters
start (array) – First entry in the range.
stop (array) – Final entry in the range.
num (int) – Number of values to generate.
axis (int) – Axis along which the operation is performed.
dev_str (str) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Tensor of evenlyspaced values.

ivy.
matmul
(x1, x2, f=None)[source]¶ Computes the matrix product of two arrays x1 and x2.
 Parameters
x1 (array) – Input array 1.
x2 (array) – Input array 2.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
The matrix product of the input arrays.

ivy.
maximum
(x, y, f=None)[source]¶ Returns the max of x and y (i.e. x > y ? x : y) elementwise.
 Parameters
x (array) – Input array containing elements to maximum threshold.
y (array) – Tensor containing maximum values, must be broadcastable to x.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
An array with the elements of x, but clipped to not be lower than the y values.

ivy.
meshgrid
(*xs, indexing='ij', f=None)[source]¶ Broadcasts parameters for evaluation on an ND grid.
 Parameters
xs (sequence of arrays) – input arrays
indexing (str, optional) – The indexing method, either ‘xy’ or ‘ij’. Default is ‘ij’.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
list of ND coordinate arrays for evaluating expressions on an ND grid

ivy.
minimum
(x, y, f=None)[source]¶ Returns the min of x and y (i.e. x < y ? x : y) elementwise.
 Parameters
x (array) – Input array containing elements to minimum threshold.
y (array) – Tensor containing minimum values, must be broadcastable to x.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
An array with the elements of x, but clipped to not exceed the y values.

ivy.
one_hot
(indices, depth, dev_str=None, f=None)[source]¶ Returns a onehot array :param indices: Indices for where the ones should be scattered [batch_shape, dim] :type indices: array :param depth: Scalar defining the depth of the onehot dimension. :type depth: int :param dev_str: device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Same as x if None. :type dev_str: str, optional :param f: Machine learning framework. Inferred from inputs if None. :type f: ml_framework, optional :return: Tensor of zeros with the same shape and type as a, unless dtype provided which overrides.

ivy.
ones
(shape, dtype_str='float32', dev_str=None, f=None)[source]¶ Returns a new array of given shape and type, filled with ones.
 Parameters
shape (sequence of ints) – Shape of the new array, e.g. (2, 3).
dtype_str – The desired datatype for the array in string format, i.e. ‘float32’ or ‘int64’.
Default is ‘float32’. :type dtype_str: datatype string, optional :param dev_str: device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc.. :type dev_str: str :param f: Machine learning framework. Inferred from inputs if None. :type f: ml_framework, optional :return: Tensor of ones with the given shape and dtype_str.

ivy.
ones_like
(x, dtype_str=None, dev_str=None, f=None)[source]¶ Returns an array of ones with the same shape and type as x, unless dtype_str provided which overrides.
 Parameters
x (array) – The shape and datatype of a define these same attributes of the returned array.
dtype_str (datatype string, optional) – The desired datatype for the array in string format, i.e. ‘float32’ or ‘int64’. If not given, then the type of the original array is used.
dev_str (str, optional) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Same as x if None.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Tensor of zeros with the same shape and type as a, unless dtype_str provided which overrides.

ivy.
reshape
(x, newshape, f=None)[source]¶ Gives a new shape to an array without changing its data.
 Parameters
x (array) – Tensor to be reshaped.
newshape (sequence of ints) – The new shape should be compatible with the original shape. One shape dimension can be 1. In this case, the value is inferred from the length of the array and remaining dimensions.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Reshaped array.

ivy.
round
(x, f=None)[source]¶ Rounds the values of an array to the nearest integer, elementwise.
 Parameters
x (array) – Input array containing elements to round.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
An array of the same shape and type as x, with the elements rounded to integers.

ivy.
scatter_flat
(indices, updates, size, reduction='sum', dev_str=None, f=None)[source]¶ Scatter flat updates into a new flat array according to flat indices.
 Parameters
indices (array) – Indices for the new values to occupy.
updates (array) – Values for the new array to hold.
size (int) – The size of the result.
reduction (str) – The reduction method for the scatter, one of ‘sum’, ‘min’, ‘max’ or ‘replace’
dev_str (str, optional) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Same as updates if None.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
New array of given shape, with the values scattered at the indices.

ivy.
scatter_nd
(indices, updates, shape, reduction='sum', dev_str=None, f=None)[source]¶ Scatter updates into a new array according to indices.
 Parameters
indices (array) – Indices for the new values to occupy.
updates (array) – Values for the new array to hold.
shape (sequence of ints) – The shape of the result.
reduction (str) – The reduction method for the scatter, one of ‘sum’, ‘min’ or ‘max’
dev_str (str, optional) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Same as updates if None.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
New array of given shape, with the values scattered at the indices.

ivy.
shape
(x, as_array=False, f=None)[source]¶ Returns the shape of the array x.
 Parameters
x (array) – Input array to infer the shape of.
as_array (bool, optional) – Whether to return the shape as a array, default False.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Shape of the array

ivy.
split
(x, num_sections=None, axis=0, f=None)[source]¶ Splits an array into multiple subarrays.
 Parameters
x (array) – Tensor to be divided into subarrays.
num_sections (int, optional) – Number of equal arrays to divide the array into, along the given axis. Size of axis dimension must be multiple of num_sections. Default is to divide into as many arrays as the axis dimension.
axis (int, optional) – The axis along which to split, default is 0.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
A list of subarrays.

ivy.
squeeze
(x, axis=None, f=None)[source]¶ Removes a singledimensional entry from the shape of an array.
 Parameters
x (array) – Input data.
axis (int, optional) – Index for one of the singledimensional entries in the shape. If an axis is selected with shape entry greater than one, an error is raised.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
The input array, but with all (axis=None) or one (axis is int) of the dimensions of length 1 removed.

ivy.
stack
(xs, axis=0, f=None)[source]¶ Joins a sequence of arrays along a new axis. The axis parameter specifies the index of the new axis in the dimensions of the result. For example, if axis=0, it will be the first dimension and if axis=1, it will be the last dimension.
 Parameters
xs (sequence of arrays) – Input arrays, each array must have the same shape.
axis (int, optional) – The axis in the result array along which the input arrays are stacked.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
The stacked array has one more dimension than the input arrays.

ivy.
str_to_dev
(dev_str, f=None)[source]¶ Convert device string representation to native device type.
 Parameters
dev_str (str) – The device string to conver to native device handle.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Native device handle.

ivy.
swapaxes
(x, axis0, axis1, f=None)[source]¶ Interchange two axes of an array.
 Parameters
x (array) – Input array.
axis0 (int) – First axis to be swapped.
axis1 (int) – Second axis to be swapped.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
x with its axes permuted.

ivy.
tile
(x, reps, f=None)[source]¶ Constructs an array by repeating x the number of times given by reps.
 Parameters
x (array) – Input array.
reps (sequence) – The number of repetitions of x along each axis.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
The tiled output array.

ivy.
to_dev
(x, dev_str=None, f=None)[source]¶ Move the input array x to the desired device, specified by device string.
 Parameters
x (array) – Array to move onto the device.
dev_str (str, optional) – device to move the array to ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Keep same device if None.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
The array x, but now placed on the target device.

ivy.
to_list
(x, f=None)[source]¶ Creates a (possibly nested) list from input array.
 Parameters
x (array) – Input array.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
A list representation of the input array.

ivy.
to_numpy
(x, f=None)[source]¶ Converts array into a numpy array.
 Parameters
x (array) – Input array.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
A numpy array.

ivy.
tpu_is_available
(f=None)[source]¶ Determine whether a TPU is available to use, with the backend framework.
 Parameters
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Boolean, as to whether a tpu is available.

ivy.
transpose
(x, axes=None, f=None)[source]¶ Permutes the dimensions of an array.
 Parameters
x (array) – Input array.
axes (sequence of ints of length N) – By default, reverse the dimensions, otherwise permute the axes according to the values given.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
x with its axes permuted.

ivy.
unstack
(x, axis, f=None)[source]¶ Unpacks the given dimension of a rankR array into rank(R1) arrays.
 Parameters
x (array) – Input array to unstack.
axis (int) – Axis for which to unpack the array.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
List of arrays, unpacked along specified dimensions.

ivy.
where
(condition, x1, x2, f=None)[source]¶ Returns elements chosen from x or y depending on condition.
 Parameters
condition (bool array) – Where True, yield x1, otherwise yield x2.
x1 (array) – values from which to choose when condition is True.
x2 (array) – values from which to choose when condition is False.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
An array with elements from x1 where condition is True, and elements from x2 elsewhere.

ivy.
zero_pad
(x, pad_width, f=None)[source]¶ Pads an array with zeros.
 Parameters
x (array) – Input array to pad.
pad_width (sequence of tuples of ints) – Number of values padded to the edges of each axis. Specified as ((before_1, after_1), … (before_N, after_N)), where N is number of axes of x.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Padded array of rank equal to x with shape increased according to pad_width.

ivy.
zeros
(shape, dtype_str='float32', dev_str=None, f=None)[source]¶ Return a new array of given shape and type, filled with zeros.
 Parameters
shape (sequence of ints) – Shape of the new array, e.g. (2, 3).
dtype_str – The desired datatype for the array in string format, i.e. ‘float32’ or ‘int64’.
Default is ‘float32’. :type dtype_str: datatype string, optional :param dev_str: device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc.. :type dev_str: str :param f: Machine learning framework. Inferred from inputs if None. :type f: ml_framework, optional :return: Tensor of zeros with the given shape and dtype_str.

ivy.
zeros_like
(x, dtype_str=None, dev_str=None, f=None)[source]¶ Returns an array of zeros with the same shape and type as x, unless dtype_str provided which overrides.
 Parameters
x (array) – The shape and datatype of x define these same attributes of the returned array.
dtype_str (datatype string, optional) – The desired datatype for the array in string format, i.e. ‘float32’ or ‘int64’. If not given, then the type of the original array is used.
dev_str (str, optional) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Same as x if None.
f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.
 Returns
Tensor of zeros with the same shape and type as a, unless dtype_str provided which overrides.
 array
 is_array
 to_numpy
 to_list
 shape
 get_num_dims
 minimum
 maximum
 clip
 round
 floormod
 floor
 ceil
 abs
 argmax
 argmin
 argsort
 cast
 arange
 linspace
 concatenate
 flip
 stack
 unstack
 split
 tile
 constant_pad
 zero_pad
 swapaxes
 transpose
 expand_dims
 where
 indices_where
 isnan
 reshape
 broadcast_to
 squeeze
 zeros
 zeros_like
 ones
 ones_like
 one_hot
 cross
 matmul
 cumsum
 cumprod
 identity
 meshgrid
 scatter_flat
 scatter_nd
 gather
 gather_nd
 dev
 to_dev
 dev_to_str
 str_to_dev
 dev_str
 gpu_is_available
 tpu_is_available
 dtype
 dtype_to_str
 dtype_str
 compile_fn