array#

ivy.array(obj, /, *, copy=None, dtype=None, device=None, out=None)[source]#

Convert the input to an array.

Parameters:
  • obj (Union[Array, NativeArray, Shape, NativeShape, bool, int, float, NestedSequence, TypeVar(SupportsBufferProtocol), ndarray]) – input data, in any form that can be converted to an array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays.

  • copy (Optional[bool], default: None) – boolean, indicating whether or not to copy the input. Default: None.

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

  • device (Optional[Union[Device, NativeDevice]], default: None) – device on which to place the created array. 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 interpretation of x.

Examples

With list of lists as input:

>>> ivy.asarray([[1,2],[3,4]])
ivy.array([[1, 2],
           [3, 4]])

With tuple of lists as input:

>>> ivy.asarray(([1.4,5.6,5.5],[3.1,9.1,7.5]))
ivy.array([[1.39999998, 5.5999999 , 5.5       ],
           [3.0999999 , 9.10000038, 7.5       ]])

With ndarray as input:

>>> x = ivy.np.ndarray(shape=(2,2), order='C')
>>> ivy.asarray(x)
ivy.array([[6.90786433e-310, 6.90786433e-310],
           [6.90786433e-310, 6.90786433e-310]])

With ivy.Container as input:

>>> x = ivy.Container(a = [(1,2),(3,4),(5,6)], b = ((1,2,3),(4,5,6)))
>>> ivy.asarray(x)
{
    a: ivy.array([[1, 2],[3, 4], [5, 6]]),
    b: ivy.array([[1, 2, 3],
               [4, 5, 6]])
}

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

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.