python - How to create a range of numbers with a given increment -


i want know whether there equivalent statement in lists following. in matlab following

fid = fopen('inc.txt','w') init =1;inc = 5; final=51; = init:inc:final l = length(a) = 1:l    fprintf(fid,'%d\n',a(i)); end fclose(fid); 

in short have initial value, final value , increment. need create array (i read equivalent lists in python) , print file.

in python, range(start, stop + 1, step) can used matlab's start:step:stop command. unlike matlab's functionality, however, range works when start, step, , stop integers. if want parallel function works floating-point values, try arange command numpy:

import numpy np  open('numbers.txt', 'w') handle:     n in np.arange(1, 5, 0.1):         handle.write('{}\n'.format(n)) 

keep in mind that, unlike matlab, range , np.arange both expect arguments in order start, stop, step. keep in mind that, unlike matlab syntax, range , np.arange both stop current value greater or equal to stop value.

http://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -