sklearn.utils.as_float_array

sklearn.utils.as_float_array(X, copy=True, force_all_finite=True)[source]

Converts 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}
copybool, optional

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.

force_all_finiteboolean or ‘allow-nan’, (default=True)

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

  • True: Force all values of X to be finite.

  • False: accept both np.inf and np.nan in X.

  • ‘allow-nan’: accept only np.nan values in X. Values cannot be infinite.

New in version 0.20: force_all_finite accepts the string 'allow-nan'.

Returns
XT{array, sparse matrix}

An array of type np.float