sin(x)TypeError:只能将size-1数组转换为Python标量

时间:2018-05-04 11:24:19

标签: python python-3.x

in[]:x=linspace(0,2*pi,50)

in[]:plot(x,sin(x))

Traceback (most recent call last):


  File "<ipython-input-55-3271d4c7a0b1>", line 1, in <module>
    plot(x,tan(x))

TypeError: only size-1 arrays can be converted to Python scalars

1 个答案:

答案 0 :(得分:0)

使用numpy库这应该有用 import numpy as np import matplotlib.pyplot as plt
x=np.linspace(0,2*np.pi,50) plt.plot(x,np.sin(x))