-2

I need to create a list from 1 to n numbers in a uniform interval.For example, the length of the list is 6 and I need with an interval of 2,it needs to create 6 numbers in uniform intervals. the interval and size of list are dynamic values.

l=[1,3,5,7,9,11]

I tried np.arange() and np.linespace() but they don't accomplish what I need.I am wondering whether there is any function to do this

Sri Test
  • 389
  • 1
  • 4
  • 21

1 Answers1

2

I believe you can do that with np.arange(), but I am unable to get the specifics of your question, but for now, given a dynamic start number, interval value and number of elements for the list, you can do something like

import numpy as np
start = 1
n = 6
interval = 2
l = np.arange(start, interval * n , interval)

Else if your start and final number are given, you can edit the above for the same too. The same can be accomplished with range() function too, with the same parameters as above, and

l = list(range(start, interval*n, interval))

edit:- you can also do interval*n + 1, if the list has to be inclusive of the number at the end.