Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Translating the values of one data set to another

I was wondering how i could ‘translate’ the values of one data set to another. Here is what I mean:

I have a data set of values that I would like to translate to midi pitches. This specific instrument in midi has a range of 33 through 128. I would like to translate values in my data set so they would fit in this range. For example: if I have a value that is the exact average of my data set, I want it to translate to 80.5 (average of this midi data set). Midi only accepts rounded numbers, but that’s beside the point.

I reckon I need a factor of some sorts. I’ve tried to come up with the correct one, but obviously it changes depending on the value and even depending on the data set. Meaning, if the minimum value of the data set is 33 and the maximum is 128, I could use factor 1. However, if the minimum is 33 and the maximum is 100, I can still use factor 1 with the value 33, but not with 100.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any ideas?

>Solution :

This might help.

Example with regular lists:

X = [1,2,3,4,5,6,7,8,9,10]
minX = min(X)
maxX = max(X)
Y = []
for x in X:
    y = (((x-minX) * (128-33)) / (maxX-minX)) + 33
    Y.append(y)

print(Y)
Y = [33.0, 43.55555555555556, 54.111111111111114, 64.66666666666667, 75.22222222222223, 85.77777777777777, 96.33333333333334, 106.88888888888889, 117.44444444444444, 128.0]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading