nws_tools.normalize

nws_tools.normalize(arr, vmin=0, vmax=1)[source]

Re-scales a NumPy ndarray

Parameters:

arr : NumPy ndarray

An array of size > 1 (shape can be arbitrary)

vmin : float

Floating point number representing the lower normalization bound. (Note that it has to hold that vmin < vmax)

vmin : float

Floating point number representing the upper normalization bound. (Note that it has to hold that vmin < vmax)

Returns:

arrn : NumPy ndarray

Scaled version of the input array arr, such that arrn.min() == vmin and arrn.max() == vmax

See also

None

Notes

In contrast to Matplotlib’s Normalize, all values of the input array are re-scaled, even if outside the specified bounds. For instance, if arr.min() == -1 and arr.max() == 0.5 then calling normalize with bounds vmin = 0 and vmax = 1 will result in an array arrn satisfying arrn.min() == 0 and arrn.max() == 1.

Examples

>>> arr = array([[-1,.2],[100,0]])
>>> arrn = normalize(arr,vmin=-10,vmax=12)
>>> arrn 
array([[-10.        ,  -9.73861386],
       [ 12.        , -10.        ]])