簡體   English   中英

關於 scipy.interpolate.interp1d 的問題

[英]Question about scipy.interpolate.interp1d

我想做線性縮放,例如:有一個序列A=[1,2,3,4],所以A的長度是4,我想做線性縮放做一個新的序列B(對比A ,B 的長度可能是 0.5 倍或 1.1 倍或 1.5 倍等....) 例如:假設縮放率為 7/4,則 B 的長度為 4 * ( 7/4) = 7 使用線性縮放,B序列的結果必須是B=[1, 1.5, 2, 2.5, 3, 3.5,4] 如何使用scipy.interpolate.interp1d來做到這一點? 或者還有其他 function 可以做到嗎? 輸入 A 得到 output B (任意縮放率)謝謝!

由於語言能力的原因,很抱歉我無法准確地描述我想要什么。 好吧,我已經完成了這個 function:

enter code here
#vec[0]&vec[-1] will not change
#num is the numbers you want to add to vec
#num cant > vec
#It's Linear zoom function
#just change length=len(vec)-num can do Linear reduction! 

def linscale(vec,num): 
    ans=[ ]   
    length=len(vec)+num
    VL=len(vec)-1
    AL=length-1
    count=0
    for i in range(length-2):
     count+= VL/AL
     if int(count)/count==1:
      value=vec[int(count)] 
      ans.append(value)
     elif int(count)/count!=1:
      new=int(count)
      if new==0:
       value=(VL*vec[new+1]+(AL-VL)*vec[new])/AL 
       ans.append(value)
      elif new!=0:
       value=((count-new)*vec[new+1]+((new+1)-count)*vec[new])
       ans.append(value)

    ans.insert(0,vec[0])
    ans.insert(AL,vec[-1])
    return ans 
-------------------------------------------------
test=[1,2,3,4]
print(linscale(test,3)) 
print(linscale(test,2)) 

[1, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0]
[1, 1.6, 2.2, 2.8, 3.4, 4.0]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM