dpnp.ndarray.astype

ndarray.astype(dtype, order='K', casting='unsafe', subok=True, copy=True)

Copy the array with data type casting.

Refer to dpnp.astype for full documentation.

Parameters:
  • x1 ({dpnp.ndarray, usm_ndarray}) -- Array data type casting.

  • dtype (dtype) -- Target data type.

  • order ({"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.

  • copy ({bool}, optional) -- If it is False and no cast happens, then this method returns the array itself. Otherwise, a copy is returned.

  • 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.

  • copy -- By default, astype always returns a newly allocated array. If this is set to False, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy.

Returns:

arr_t -- Unless copy is False and the other conditions for returning the input array are satisfied, arr_t is a new array of the same shape as the input array, with dtype, order given by dtype, order.

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])