1
vec4=np.linspace(0,100,10)
print(vec4)

Running this results in

[  0.          11.11111111  22.22222222  33.33333333  44.44444444
  55.55555556  66.66666667  77.77777778  88.88888889 100.        ]

Why is this not giving integers? I was expecting this below

[1    2    3    4    ..so on]
martineau
  • 119,623
  • 25
  • 170
  • 301
xxxstack
  • 11
  • 2
  • Does that array match the documentation? Are there 10 elements? Equally spaced? Start and end with 0 and 100. Look at something smaller like `[0,1,2,3,4]`. 4 or 5 elements? – hpaulj Jan 30 '22 at 18:50

1 Answers1

1

When you call linspace like np.linspace(start,stop,n_elements), you are telling numpy to create an array of length n_elements that have an equal distance and that include start and stop. Due to including start and stop, the space/distance is equal to `(stop-start)/(n_elements - 1)? which should explain the numbers you got.

If you just want integers, you can use np.arange(start, end, step), however, this would not include end. Or, for you example, you can do np.linspace(0, 100, 11).astype(int)

Simon Hawe
  • 3,968
  • 6
  • 14