numpy中线性积分的步进函数 [英] Step function with linear inteval in numpy
本文介绍了numpy中线性积分的步进函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在numpy中实现具有以下定义的步进功能:
I want to implement for a step function in numpy with the definition:
推荐答案
由于另一个答案未实现问题中的功能,因此以下是正确的解决方案:
Since the other answer does not implement the function in the question, here is a correct soluton:
import numpy as np
import matplotlib.pyplot as plt
x= np.linspace(0., 50., 1001)
f = lambda x0, x1: np.piecewise(x, [x < x0, (x >= x0) & (x <= x1), x > x1],
[0., lambda x: x/x0, 1.])
plt.plot(x, f(10, 30))
plt.show()
这篇关于numpy中线性积分的步进函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文