|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我想写一个可以画对数函数的程序:
- import math as m
- import numpy as np
- import matplotlib.pyplot as plt
- "y = log(a)x"
- a = float(input("底数:"))
- min0 = float(input("最小值:"))
- max0 = float(input("最大值:"))
- x = np.arange(min0 , max0 , 0.00001)
- y = m.log(x , a)
- plt.plot(x , y)
- plt.xlabel("x")
- plt.ylabel("y")
- plt.tick_params(axis = "both" , labelsize = 16)
- plt.show()
复制代码
然后
- Traceback (most recent call last):
- File "C:\Users\Administrator\Desktop\asdf.py", line 11, in <module>
- y = m.log(x , a)
- TypeError: only size-1 arrays can be converted to Python scalars
复制代码
我要怎么办?
- import math as m
- import numpy as np
- import matplotlib.pyplot as plt
- "y = log(a)x"
- a = float(input("底数:"))
- min0 = float(input("最小值:"))
- max0 = float(input("最大值:"))
- x = np.arange(min0 , max0 , 0.00001)
- y = [m.log(a,e) for e in x]
- plt.plot(x , y)
- plt.xlabel("x")
- plt.ylabel("y")
- plt.tick_params(axis = "both" , labelsize = 16)
- plt.show()
复制代码
|
|