Tiffany Lam
Tiffany Lam

Reputation: 9

Create a list of elements 0 to 1 with a specified number of elements

How do I use Python to create a list of a specified number of elements that increases from 0 to 1?

To be more clear, I want to generate a list of 3270 elements that increase linearly from 0 to 1. Since I need such a large list, I think it's improbable for me to specify the step.

I tried to use list(range()), but that only works for integers.

Upvotes: 0

Views: 445

Answers (2)

Hugh Bothwell
Hugh Bothwell

Reputation: 56624

import numpy as np

elements = np.linspace(0., 1., 3270)

Upvotes: 0

Amadan
Amadan

Reputation: 198294

[x / 3270.0 for x in xrange(0, 3271)]

Upvotes: 3

Related Questions