from scipy.interpolate import interp1d
import numpy as np
# 定義已知的 X 和 Y 值
x = np.array([1, 2, 3])
y = np.array([4, 5, 6])
# 建立一個插值函數
f = interp1d(x, y)
# 定義需要插值的 X 值
x_new = np.array([1.5, 2.5])
# 對 X 值進行插值
y_new = f(x_new)
print(“插值結果:”, y_new)

用polyfit作外插
import numpy as np
# 定义已知的 X 和 Y 值
x = np.array([1, 2, 3])
y = np.array([4, 5, 6])
# 使用 polyfit 函数拟合多项式
coefs = np.polyfit(x, y, 2)
# 使用 numpy.poly1d 函数创建多项式对象
p = np.poly1d(coefs)
# 定义需要外插的 X 值
x_new = np.array([0, 4])
# 使用多项式对象的差值函数对 X 值进行外插
y_new = p(x_new)
print(“外插结果:”, y_new)

推薦hahow線上學習python: https://igrape.net/30afN




![Python 讀取 DOCX 圖片關聯:qn+find/findall 與 XPath 的實戰對照 from lxml import etree ; from docx.oxml.ns import qn; lxml.etree._Element.findall( f”.//{ qn(‘a:blip’) }” ) ; .get( qn(“r:embed”) ) #獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’) ; lxml.etree._Element.xpath( “//a:blip/@r:embed”, namespaces = NS) #/@r:embed = 獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’),使用.findall() 要先.findall()獲取List[_Element],再迴圈_Element.get()獲取屬性值, .xpath() 第一個參數path 使用”//a:blip/@r:embed” ,可直接獲取屬性值(List[str]如: [‘rId4’, ‘rId5’]) ; 如何對docx真實移除圖片瘦身? Python 讀取 DOCX 圖片關聯:qn+find/findall 與 XPath 的實戰對照 from lxml import etree ; from docx.oxml.ns import qn; lxml.etree._Element.findall( f”.//{ qn(‘a:blip’) }” ) ; .get( qn(“r:embed”) ) #獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’) ; lxml.etree._Element.xpath( “//a:blip/@r:embed”, namespaces = NS) #/@r:embed = 獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’),使用.findall() 要先.findall()獲取List[_Element],再迴圈_Element.get()獲取屬性值, .xpath() 第一個參數path 使用”//a:blip/@r:embed” ,可直接獲取屬性值(List[str]如: [‘rId4’, ‘rId5’]) ; 如何對docx真實移除圖片瘦身?](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/11/20251119130848_0_3fbf6b.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


![Python:如何用pandas.concat() 合併兩個DataFrame並重置index? pd.concat([df1, df2]) .reset_index(drop=True) ; pd.concat([df1, df2], ignore_index=True) Python:如何用pandas.concat() 合併兩個DataFrame並重置index? pd.concat([df1, df2]) .reset_index(drop=True) ; pd.concat([df1, df2], ignore_index=True)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2023/03/20230311123232_5.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言