Python:np.矢量化返回“float”

2024-06-02 08:13:51 发布

您现在位置:Python中文网/ 问答频道 /正文

运行以下代码:

import matplotlib.pyplot as plt
import numpy as np

def xon (ton, t):
    if ton <= t:
        return (t-ton)/5
    else:
        return 0

vxon = np.vectorize(xon)
t = np.linspace(0, 49, 50)    
xontest = vxon(0, t)
plt.plot(t, xontest, '-')
plt.show()

我明白剧情: enter image description here

但当我试图绘制ton值时,它与零不同,例如:

^{pr2}$

该图似乎将所有xon值四舍五入为整数:

enter image description here

我的代码中是什么导致了这种行为?在


Tags: 代码importnumpyreturnifmatplotlibdefas