Home > OS >  List range of nums divided by N
List range of nums divided by N

Time:02-16

I want a list comprehension that list a range of numbers from 1 to 100, divided by N.

I want to be able to swap out the N number

So if divided by 10: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Divided by 5: [2, 4, 6, 8, 10]

Divided by 3: [3.33, 6.66, 9.99]

Code:

nums = [i for i in range(1, 10)]

CodePudding user response:

This should do what you want !

import numpy as np
N = 3 
[i for i in np.linspace(10,10/N,N)[::-1]]
  • Related