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 如何用pandas.Series.nsmallest() 找到n個與target差距最小的index?再從中找到距離idxmax最近的index?避免誤抓sidelobes的index? targetIdx = (serMean-target_value).abs().nsmallest(n).index.tolist() ;Series切片: .loc[標籤名1:標籤名2] (會含標籤名2) ; .iloc[位置1:位置2] (不含位置2) Python 如何用pandas.Series.nsmallest() 找到n個與target差距最小的index?再從中找到距離idxmax最近的index?避免誤抓sidelobes的index? targetIdx = (serMean-target_value).abs().nsmallest(n).index.tolist() ;Series切片: .loc[標籤名1:標籤名2] (會含標籤名2) ; .iloc[位置1:位置2] (不含位置2)](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/02/20230222082954_53.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python 如何做excel的樞紐分析? pandas.pivot_table() 或 pandas.DataFrame .groupby() ; 如何指定欄位順序? DataFrame.reindex() ; .sortlevel() ; DataFrame[[col1, col2, col3 ]] ; df.columns.map() ; 如何顯示所有欄? pandas.set_option (“display.max_columns”, None) Python 如何做excel的樞紐分析? pandas.pivot_table() 或 pandas.DataFrame .groupby() ; 如何指定欄位順序? DataFrame.reindex() ; .sortlevel() ; DataFrame[[col1, col2, col3 ]] ; df.columns.map() ; 如何顯示所有欄? pandas.set_option (“display.max_columns”, None)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2023/03/20230323101848_80.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言