有沒有辦法轉換數字范圍?
我需要將線性范圍(0-1)轉換為對數范圍(100*10^-12 - 1),這樣我就可以在繪圖上放置一條可移動的水平線(https://plotly.com/python /horizo??ntal-vertical-shapes/#horizo??ntal-and-vertical-lines-in-dash)。
據我所知,我不能讓我的滑塊對數開始(https://dash.plotly.com/dash-core-components/slider#non-linear-slider-and-updatemode)。
我試過正常化。我不確定這是否是正確的詞,但基本上將我的價值放在:
f(x) = log10(x * (max-min) min)
在哪里:
x 是被轉換的線性值
max 是對數刻度的最大值 (1)
min 是對數刻度的最小值 (100*10^-12)
但是當我期望 10*10^-9 時,f(.2) = .447。
有沒有辦法做到這一點(或者更好的方法在情節上放置一條可移動的水平線)?
uj5u.com熱心網友回復:
順便說一句,100*10^-12== 10^-10
。
似乎您想取范圍內的值的對數10^-10..1
以將它們映射到0..1
范圍內,反之亦然?
Y = A * log10(B * X)
替換最終值:
0 = A * log10(B * 10^-10) = A * (log10(B) - 10)
log10(B) = 10
B = 10^10
1 = A * log10(10^10 * 1) = A * 10
A = 0.1
所以公式是
Y = 0.1 * log10(10^10 * X) =
1 0.1 * log10(X)
逆公式
10*Y = log10(10^10 * X)
10^(10*Y) = 10^10 * X
X = 10^(10*Y) * 10^-10 =
10^(10*Y-10)
使用您的示例 Y=0.2,我們得到 X = 10^-8,如預期
from math import log10
for i in range(-10, 1):
X = 10**i
Y = 1 0.1 * log10(X)
print(Y)
print()
for i in range(0, 11):
Y = i / 10
X = 10**(10*Y-10)
print(X)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/507870.html