Smallest float type to contain range of arr after scaling
Scaling that will be applied to arr is (arr - inter) / slope.
Note that slope and inter get promoted to 1D arrays for this purpose to avoid the numpy scalar casting rules, which prevent scalars upcasting the array.
Parameters : | arr : array-like
slope : array-like, optional
inter : array-like, optional
default : numpy type, optional
|
---|---|
Returns : | ftype : numpy type
|
Examples
>>> arr = np.array([0, 1, 2], dtype=np.int16)
>>> best_write_scale_ftype(arr, 1, 0) is np.float32
True
Specify higher default return value
>>> best_write_scale_ftype(arr, 1, 0, default=np.float64) is np.float64
True
Even large values that don’t overflow don’t change output
>>> arr = np.array([0, np.finfo(np.float32).max], dtype=np.float32)
>>> best_write_scale_ftype(arr, 1, 0) is np.float32
True
Scaling > 1 reduces output values, so no upcast needed
>>> best_write_scale_ftype(arr, np.float32(2), 0) is np.float32
True
Scaling < 1 increases values, so upcast may be needed (and is here)
>>> best_write_scale_ftype(arr, np.float32(0.5), 0) is np.float64
True