-5

I have some constant , for example, 0.5. So i need to create a numpy array where first element will be equal constant (array[0]=0.5) and next one will be 1, 1.5, 2, 2.5... (previous element plus constant). Lenght of this sequence must be 795. Array what i need looks like:

array = ([0.5,1,1.5,2,2.5.....])

thank you in advance

2 Answers2

2

Check out this answer - basically what you want is

import numpy
numpy.arange(0.5, 0.5 + 795 * 0.5, 0.5)
Alex
  • 121
  • 1
  • 3
0

Using numpy.linspace:

import numpy as np

res = np.linspace(0.5, 795*0.5, num=795)

array([   0.5,    1. ,    1.5,    2. ,    2.5,    3. ,    3.5,    4. ,
      ...
        396.5,  397. ,  397.5])
jpp
  • 159,742
  • 34
  • 281
  • 339