def ellipse(numPoints, genX=np.linspace, HALF_WIDTH=10, HALF_HEIGHT=6.5):
xs = 10.*genX(-1,1,numPoints)
ys = 6.5*np.sqrt(1-(xs**2))
return(xs, ys, "-")
Run Code Online (Sandbox Code Playgroud)
我收到一个错误,指出在squareroot中遇到无效值.我看不出它是什么.
sqrt(0) = 0
6.5*sqrt(1- (-1**2)) = 0
Run Code Online (Sandbox Code Playgroud)
他们应该工作,但y值有问题,他们正在返回"南"
可能xs**2返回一个数字> 1sqrt,负数将返回nan(不是数字)
>>> import numpy as np
>>> np.sqrt(-1)
nan
Run Code Online (Sandbox Code Playgroud)
如果我是对的numpy提供了复数函数,我认为这是表示sqrt(x)的唯一方法,其中x <0
| 归档时间: |
|
| 查看次数: |
10331 次 |
| 最近记录: |