Scaling tools¶
Functions
|
Linearly rescale input from its original range to a new range. |
- linearscaling(x, new_min, new_max, old_min=None, old_max=None, axis=None)¶
Linearly rescale input from its original range to a new range.
- Parameters
x (scalar-or-array) – scalar or arrays of scalars in
[old_min, old_max]
of shape(n, *shape)
new_min (scalar-or-array) – scalar or array of shape
(*shape,)
new_max (scalar-or-array) – scalar or array of shape
(*shape,)
old_min (scalar-or-array?) – (
default=x.min()
)old_max (scalar-or-array?) – (
default=x.max()
)axis (int?) – (
default=None
)
- Returns
scalar or array of scalars in
[new_min, new_max]
of shape(n, *shape)
Example
>>> linearscaling(0, -10, 10, 0, 1) -10.0
When the original range is not passed on, it is considered to be the interval in which the input values are.
>>> x = numpy.arange(0, 1, 0.1) >>> linearscaling(x, 0, 10) array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) >>> linearscaling(x, 0, 10, 0, 2) array([0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5])
Linear scaling can be performed on dfferent series of data having different ranges provided that the new minima/maxima are specfied for each serie.
>>> new_min = numpy.array([0, 0]) >>> new_max = numpy.array([1, 100]) >>> old_min = numpy.array([0, 0]) >>> old_max = numpy.array([10, 10]) >>> x = numpy.arange(0, 1, 0.1).reshape(5, 2) >>> x array([[0. , 0.1], [0.2, 0.3], [0.4, 0.5], [0.6, 0.7], [0.8, 0.9]]) >>> linearscaling(x, new_min, new_max, old_min, old_max) array([[ 0.1, 10. ], [ 0.2, 20. ], [ 0.3, 30. ], [ 0.4, 40. ], [ 0.5, 50. ]])