copy_array#

ivy.copy_array(x, /, *, to_ivy_array=True, out=None)[source]#

Copy an array.

Parameters:
  • x (Union[Array, NativeArray]) – array, input array containing elements to copy.

  • to_ivy_array (bool, default: True) – boolean, if True the returned array will be an ivy.Array object otherwise returns an ivy.NativeArray object (i.e. a torch.tensor, np.array, etc., depending on the backend), defaults to 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 – a copy of the input array x.

Examples

With one ivy.Array input:

>>> x = ivy.array([-1, 0, 1])
>>> y = ivy.copy_array(x)
>>> print(y)
ivy.array([-1, 0, 1])
>>> x = ivy.array([1, 0, 1, 1])
>>> y = ivy.copy_array(x)
>>> print(y)
ivy.array([1, 0, 1, 1])
>>> x = ivy.array([1, 0, 1, -1])
>>> y = ivy.zeros((1, 4))
>>> ivy.copy_array(x, out=y)
>>> print(y)
ivy.array([1, 0, 1, -1])
>>> x = ivy.array([1, 0, 1, 1])
>>> ivy.copy_array(x, out=x)
>>> print(x)
ivy.array([1, 0, 1, 1])

With one ivy.Container input:

>>> x = ivy.Container(a=ivy.array([-1, 0, 1]))
>>> y = ivy.copy_array(x)
>>> print(y)
{
    a: ivy.array([-1, 0, 1])
}
>>> x = ivy.Container(a=ivy.array([-1, 0, 1]),b=ivy.array([-1, 0, 1, 1, 1, 0]))
>>> y = ivy.copy_array(x)
>>> print(y)
{
    a: ivy.array([-1, 0, 1]),
    b: ivy.array([-1, 0, 1, 1, 1, 0])
}

With one ivy.Container static method:

>>> x = ivy.Container(a=ivy.array([-1, 0, 1]),b=ivy.array([-1, 0, 1, 1, 1, 0]))
>>> y = ivy.Container.static_copy_array(x)
>>> print(y)
{
    a: ivy.array([-1, 0, 1]),
    b: ivy.array([-1, 0, 1, 1, 1, 0])
}

With one ivy.Array instance method:

>>> x = ivy.array([-1, 0, 1])
>>> y = x.copy_array()
>>> print(y)
ivy.array([-1, 0, 1])
>>> x = ivy.array([1, 0, 1, 1])
>>> y = x.copy_array()
>>> print(y)
ivy.array([1, 0, 1, 1])

With ivy.Container instance method:

>>> x = ivy.Container(a=ivy.array([1, 0, 1]),b=ivy.array([-1, 0, 1, 1]))
>>> y = x.copy_array()
>>> print(y)
{
    a: ivy.array([1, 0, 1]),
    b: ivy.array([-1, 0, 1, 1])
}
Array.copy_array(self, /, *, to_ivy_array=True, out=None)[source]#

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

Parameters:
  • self (Array) – input array

  • to_ivy_array (bool, default: True) – boolean, if True the returned array will be an ivy.Array object otherwise returns an ivy.NativeArray object (i.e. a torch.tensor, np.array, etc., depending on the backend), defaults to 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 – a copy of the input array x.

Container.copy_array(self, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, to_ivy_array=True, out=None)[source]#
Return type:

Container