This is documentation for an old release of NumPy (version 1.6.0). Read this page in the documentation of the latest stable release (version > 1.17).

numpy.ndarray.astype

ndarray.astype(t)

Copy of the array, cast to a specified type.

Parameters :

t : str or dtype

Typecode or data-type to which the array is cast.

Raises :

ComplexWarning : :

When casting from complex to float or int. To avoid this, one should use a.real.astype(t).

Examples

>>> x = np.array([1, 2, 2.5])
>>> x
array([ 1. ,  2. ,  2.5])
>>> x.astype(int)
array([1, 2, 2])

Previous topic

numpy.ndarray.dumps

Next topic

numpy.ndarray.byteswap

This Page