numpy:arange 包括端点

Tho*_*uer 5 python numpy

我需要将一些 Matlab 代码转移到 P 中。我被困在一个numpy.arange我用来在给定角度(以弧度为单位)的圆弧上连续设置点的方法。

我做到了这一点(例如 x 轴上的点):

def sensor_data_arc_x():
    theta = np.arange(0, angle/2, 2*np.pi/360)
    return np.multiply(radius, np.cos(np.transpose(theta)))
Run Code Online (Sandbox Code Playgroud)

我知道numpy.arange不包括端点,尽管 Matlab 等价物包括;数组总是短一个元素,这扰乱了我的进一步计算。

有没有办法包含端点?

Pru*_*une 5

我建议您阅读有关for循环的教程——您需要的信息以及有关使用受控迭代的其他提示都在那里。为了解决您的迫切需要,只需将上限增加一个循环增量:

inc = 2*np.pi/360
theta = np.arange(0, angle/2 + inc, inc)
Run Code Online (Sandbox Code Playgroud)