nlcpy.asarray

nlcpy.asarray(a, dtype=None, order=None)[source]

Converts the input to an array.

Parameters
aarray_like

Input data, in any form that can be converted to an array. This includes scalars, lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays.

dtypedtype, optional

By default, the dtype is inferred from the input data.

order{‘C’, ‘F’}, optional

Whether to use row-major (C-style) or column-major (Fortran-style) memory representation. Defaults to ‘C’.

Returns
outndarray

Array interpretation of a. No copy is performed if the input is already an ndarray with matching and order. If a is a subclass of ndarray, a base class ndarray is returned.

See also

asanyarray

Converts the input to an array, but pass ndarray subclasses through.

Examples

Convert a list into an array:

>>> import nlcpy as vp
>>> a = [1, 2]
>>> vp.asarray(a)
array([1, 2])

Existing arrays are not copied:

>>> a = vp.array([1, 2])
>>> vp.asarray(a) is a
True

If dtype is set, array is copied only if dtype does not match:

>>> a = vp.array([1, 2], dtype=vp.float32)
>>> vp.asarray(a, dtype=vp.float32) is a
True
>>> vp.asarray(a, dtype=vp.float64) is a
False