asarray¶
- asarray(obj: array | bool | int | float | NestedSequence | SupportsBufferProtocol, /, *, dtype: dtype | None = None, device: device | None = None, copy: bool | None = None) array ¶
Convert the input to an array.
- Parameters:
obj (Union[array, bool, int, float, NestedSequence[bool | int | float], SupportsBufferProtocol]) –
object to be converted to an array. May be a Python scalar, a (possibly nested) sequence of Python scalars, or an object supporting the Python buffer protocol.
Tip
An object supporting the buffer protocol can be turned into a memoryview through
memoryview(obj)
.dtype (Optional[dtype]) –
output array data type. If
dtype
isNone
, the output array data type must be inferred from the data type(s) inobj
. If all input values are Python scalars, thenif all values are of type
bool
, the output data type must bebool
.if the values are a mixture of
bool
s andint
, the output data type must be the default integer data type.if one or more values are
float
s, the output data type must be the default floating-point data type.
Default:
None
.Note
If
dtype
is notNone
, then array conversions should obey Type Promotion Rules rules. Conversions not specified according to Type Promotion Rules rules may or may not be permitted by a conforming array library. To perform an explicit cast, usearray_api.astype()
.Note
If an input value exceeds the precision of the resolved output array data type, behavior is left unspecified and, thus, implementation-defined.
device (Optional[device]) – device on which to place the created array. If
device
isNone
andobj
is an array, the output array device must be inferred fromobj
. Default:None
.copy (Optional[bool]) – boolean indicating whether or not to copy the input. If
True
, the function must always copy. IfFalse
, the function must never copy for input which supports the buffer protocol and must raise aValueError
in case a copy would be necessary. IfNone
, the function must reuse existing memory buffer if possible and copy otherwise. Default:None
.
- Returns:
out (array) – an array containing the data from
obj
.