Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numpy: arange include endpoint

Tags:

python

numpy

I need to transfer some Matlab code into P. I got stuck at a numpy.arange I use to set points continuously on the arc of circle with a given angle (in radians).

I got this far (example for points on x-axis):

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

I know numpy.arange does not include the endpoint, although the Matlab equivalent does; the array is always one element short, which is messing up my further computations.

Is there an way to include the endpoint?

like image 999
Thomas Neubauer Avatar asked Nov 08 '18 17:11

Thomas Neubauer


Video Answer


1 Answers

I recommend that you work through a tutorial on for loops -- the information you need is there, as well as other hints on using controlled iteration. To solve your immediate need, simply increase your upper bound by one loop increment:

inc = 2*np.pi/360
theta = np.arange(0, angle/2 + inc, inc)
like image 57
Prune Avatar answered Nov 09 '22 01:11

Prune