将一个数据集的值转换为另一个

huangapple go评论76阅读模式
英文:

Translating the values of one data set to another

问题

我在想如何将一个数据集的值“翻译”到另一个数据集。我的意思是:

我有一组数值,我想将它们转换为 MIDI 音高。MIDI 中的这个特定乐器的范围是 33 到 128。我想将我的数据集中的值转换为这个范围内的值。例如:如果我有一个值恰好是我的数据集的平均值,我希望它被转换为 80.5(这个 MIDI 数据集的平均值)。MIDI 只接受四舍五入的整数,但这并不是重点。

我认为我需要某种因子。我尝试想出正确的因子,但显然它会根据值甚至根据数据集的不同而变化。这意味着,如果数据集的最小值是 33,最大值是 128,我可以使用因子 1。然而,如果最小值是 33,最大值是 100,我仍然可以使用值 33 的因子 1,但不能用于值 100。

有什么想法?

英文:

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.

Any ideas?

答案1

得分: -1

这可能会有帮助。

<br>
使用常规列表的示例:

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]
英文:

This might help.

<br>
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]

huangapple
  • 本文由 发表于 2023年2月26日 23:37:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75573072.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定