maad.util.linear_scale

maad.util.linear_scale(x, minval=0.0, maxval=1.0, axis=0)[source]

Scale the values of a vector or matrix from a user specified minimum to a user specified maximum.

Parameters:
xarray-like

numpy.array like with numbers, list or dataframe

minvalscalar, optional, default0

This minimum value is attributed to the minimum value of - the array if axis = None - each column if axis =0 - each row if axis = 1

maxvalscalar, optional, default1

This maximum value is attributed to the maximum value of - the array if axis = None - each column if axis =0 - each row if axis = 1

axisinteger, optional, default0

select if the min,max is calculated on the entire matrix (axis=None), on each column (axis=0), on each row (axis=1)

Returns:
yarray-like

numpy.array like with numbers or dataframe

References

Written by Aniruddha Kembhavi, July 11, 2007 for MATLAB, adapted by S. Haupert Dec 12, 2017 for Python

Examples

>>> a = np.array([1,2,3,4,5])
>>> maad.util.linear_scale(a, 0, 1)
    array([0.  , 0.25, 0.5 , 0.75, 1.  ])