astype¶
- astype(x: array, dtype: dtype, /, *, copy: bool = True) array ¶
Copies an array to a specified data type irrespective of Type Promotion Rules rules.
Note
Casting floating-point
NaN
andinfinity
values to integral data types is not specified and is implementation-dependent.Note
When casting a boolean input array to a numeric data type, a value of
True
must cast to a numeric value equal to1
, and a value ofFalse
must cast to a numeric value equal to0
.When casting a numeric input array to
bool
, a value of0
must cast toFalse
, and a non-zero value must cast toTrue
.- Parameters:
x (array) – array to cast.
dtype (dtype) – desired data type.
copy (bool) – specifies whether to copy an array when the specified
dtype
matches the data type of the input arrayx
. IfTrue
, a newly allocated array must always be returned. IfFalse
and the specifieddtype
matches the data type of the input array, the input array must be returned; otherwise, a newly allocated must be returned. Default:True
.
- Returns:
out (array) – an array having the specified data type. The returned array must have the same shape as
x
.