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爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件) Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件)](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250330190318_0_925655.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python: 如何求整個 pandas.DataFrame 中的最大值? pandas.DataFrame .max().max() ; 如何求最大值的index, columns? numpy.where(condition, [x, y, ]/) ; condition為一 bool_mask Python: 如何求整個 pandas.DataFrame 中的最大值? pandas.DataFrame .max().max() ; 如何求最大值的index, columns? numpy.where(condition, [x, y, ]/) ; condition為一 bool_mask](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/04/20230418154049_50.png?quality=90&zoom=2&ssl=1&resize=350%2C233)





近期留言