as_float_array (original) (raw)

sklearn.utils.as_float_array(X, *, copy=True, ensure_all_finite=True)[source]#

Convert an array-like to an array of floats.

The new dtype will be np.float32 or np.float64, depending on the original type. The function can create a copy or modify the argument depending on the argument copy.

Parameters:

X{array-like, sparse matrix}

The input data.

copybool, default=True

If True, a copy of X will be created. If False, a copy may still be returned if X’s dtype is not a floating point type.

ensure_all_finitebool or ‘allow-nan’, default=True

Whether to raise an error on np.inf, np.nan, pd.NA in X. The possibilities are:

Added in version 1.6: force_all_finite was renamed to ensure_all_finite.

Returns:

XT{ndarray, sparse matrix}

An array of type float.

Examples

from sklearn.utils import as_float_array import numpy as np array = np.array([0, 0, 1, 2, 2], dtype=np.int64) as_float_array(array) array([0., 0., 1., 2., 2.])