nums.numpy.asarray#

nums.numpy.asarray(a, dtype=None, order=None, *, like=None)#

Convert the input to an array.

aarray_like

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.

dtypedata-type, optional

By default, the data-type is inferred from the input data.

outBlockArray

Array interpretation of a. No copy is performed if the input is already a BlockArray with matching dtype and order.

NotImplementedError

If you pass a non-None value to order or like.

asanyarray : Similar function which passes through subclasses. asfarray : Convert input to a floating point ndarray. asarray_chkfinite : Similar function which checks input for NaNs and Infs. fromiter : Create an array from an iterator. fromfunction : Construct an array by executing a function on grid

positions.

Convert a list into an array:

>>> a = [1, 2]
>>> nps.asarray(a).get()
array([1, 2])

Existing arrays are not copied:

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

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

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