A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.scipy.org/doc/numpy/reference/generated/numpy.astype.html below:

numpy.astype — NumPy v2.3 Manual

numpy.astype#
numpy.astype(x, dtype, /, *, copy=True, device=None)[source]#

Copies an array to a specified data type.

This function is an Array API compatible alternative to numpy.ndarray.astype.

Parameters:
xndarray

Input NumPy array to cast. array_likes are explicitly not supported here.

dtypedtype

Data type of the result.

copybool, optional

Specifies whether to copy an array when the specified dtype matches the data type of the input array x. If True, a newly allocated array must always be returned. If False and the specified dtype matches the data type of the input array, the input array must be returned; otherwise, a newly allocated array must be returned. Defaults to True.

devicestr, optional

The device on which to place the returned array. Default: None. For Array-API interoperability only, so must be "cpu" if passed.

New in version 2.1.0.

Returns:
outndarray

An array having the specified data type.

Examples

>>> import numpy as np
>>> arr = np.array([1, 2, 3]); arr
array([1, 2, 3])
>>> np.astype(arr, np.float64)
array([1., 2., 3.])

Non-copy case:

>>> arr = np.array([1, 2, 3])
>>> arr_noncpy = np.astype(arr, arr.dtype, copy=False)
>>> np.shares_memory(arr, arr_noncpy)
True

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4