(三)scipy3.0:插值。与之前写的B样条插值差不多

"""
scipy3.0:插值。与之前写的B样条插值差不多
马玉华   2019.11.7
"""
import numpy as np
from scipy.interpolate import interp1d
import matplotlib.pyplot as plt

x = np.linspace(0,1,10)   # 0-1均匀取10个数
y = np.sin(2*np.pi*x)
func = interp1d(x,y,kind='cubic')   # cubic三阶B样条插值
x_new = np.linspace(0,1,50)
y_new = func(x_new)

print(y_new)
plt.figure()
plt.plot(x,y,'r')
plt.plot(x_new,y_new,'k')
plt.show()

输出结果:

"C:\Users\mayuhuaw\Desktop\Python数据分析-基础技术\3. scipy\venv\Scripts\python.exe" "C:/Users/mayuhuaw/Desktop/Python数据分析-基础技术/3. scipy/scipy3.0:插值.py"
[ 0.00000000e+00  1.31268478e-01  2.58058896e-01  3.79095818e-01
  4.93103803e-01  5.98807414e-01  6.94931212e-01  7.80199759e-01
  8.53337617e-01  9.13069347e-01  9.58119510e-01  9.87213058e-01
  9.99462682e-01  9.95096409e-01  9.74541587e-01  9.38225564e-01
  8.86575689e-01  8.20078818e-01  7.39913600e-01  6.47705004e-01
  5.45085433e-01  4.33687295e-01  3.15143957e-01  1.91245093e-01
  6.41081509e-02 -6.41081509e-02 -1.91245093e-01 -3.15143957e-01
 -4.33687295e-01 -5.45085433e-01 -6.47705004e-01 -7.39913600e-01
 -8.20078818e-01 -8.86575689e-01 -9.38225564e-01 -9.74541587e-01
 -9.95096409e-01 -9.99462682e-01 -9.87213058e-01 -9.58119510e-01
 -9.13069347e-01 -8.53337617e-01 -7.80199759e-01 -6.94931212e-01
 -5.98807414e-01 -4.93103803e-01 -3.79095818e-01 -2.58058896e-01
 -1.31268478e-01 -2.44929360e-16]

进程已结束,退出代码 0

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nutron-ma

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值