dpnp.ndarray.astype
method
- ndarray.astype(dtype, order='K', casting='unsafe', subok=True, copy=True, device=None)
Copy the array with data type casting.
Refer to
dpnp.astype
for full documentation.- Parameters:
dtype ({None, str, dtype object}) -- Target data type.
order ({None, "C", "F", "A", "K"}, optional) --
Row-major (C-style) or column-major (Fortran-style) order. When order is
"A"
, it uses"F"
if a is column-major and uses"C"
otherwise. And when order is"K"
, it keeps strides as closely as possible.Default:
"K"
.casting ({"no", "equiv", "safe", "same_kind", "unsafe"}, optional) --
Controls what kind of data casting may occur. Defaults to
"unsafe"
for backwards compatibility."no" means the data types should not be cast at all.
"equiv" means only byte-order changes are allowed.
"safe" means only casts which can preserve values are allowed.
"same_kind" means only safe casts or casts within a kind, like float64 to float32, are allowed.
"unsafe" means any data conversions may be done.
Default:
"unsafe"
.copy (bool, optional) --
Specifies whether to copy an array when the specified dtype matches the data type of that array. If
True
, a newly allocated array must always be returned. IfFalse
and the specified dtype matches the data type of that array, the self array must be returned; otherwise, a newly allocated array must be returned.Default:
True
.device ({None, string, SyclDevice, SyclQueue, Device}, optional) --
An array API concept of device where the output array is created. device can be
None
, a oneAPI filter selector string, an instance ofdpctl.SyclDevice
corresponding to a non-partitioned SYCL device, an instance ofdpctl.SyclQueue
, or adpctl.tensor.Device
object returned bydpnp.ndarray.device
. If the value isNone
, returned array is created on the same device as that array.Default:
None
.
- Returns:
out -- An array having the specified data type.
- Return type:
dpnp.ndarray
Limitations
Parameter subok is supported with default value. Otherwise
NotImplementedError
exception will be raised.Examples
>>> import dpnp as np >>> x = np.array([1, 2, 2.5]); x array([1. , 2. , 2.5])
>>> x.astype(int) array([1, 2, 2])