I have a function that rescales an array to values between 0.0 and 1.0, but I am stuck as to how to rescale the returned array to a user-defined new min/max range. The questions prompt is "Rewrite the rescale function so that it scales data to lie between 0.0 and 1.0 by default, but will allow the caller to specify lower and upper bounds if they want"
Below is the code for my current array, and tests. I know I will have to add an additional default min/max parameter, but I am fairly new to python, and programming in general, and I am at a loss of how to proceed. Any help is appreciated.
import numpy
def rescale(input):
revalue = []
Amax = input.max()
Amin = input.min()
print Amax
print Amin
print input
for x in input:
value = [(x-Amin)/(Amax-Amin)]
revalue.append(value)
print revalue
# Tests:
rescale(numpy.arange(10, dtype=np.float))
# Output
9.0
0.0
[ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9.]
[[0.0], [0.1111111111111111], [0.22222222222222221], [0.33333333333333331], [0.44444444444444442], [0.55555555555555558], [0.66666666666666663], [0.77777777777777779], [0.88888888888888884], [1.0]]