Calculating a range of an exact number of values in Python
Posted
by Einar
on Stack Overflow
See other posts from Stack Overflow
or by Einar
Published on 2010-03-18T11:38:19Z
Indexed on
2010/03/18
11:41 UTC
Read the original article
Hit count: 421
Hello,
I'm building a range between two numbers (floats) and I'd like this range to be of an exact fixed length (no more, no less). range
and arange
work with steps, instead. To put things into pseudo Python, this is what I'd like to achieve:
start_value = -7.5
end_value = 0.1
my_range = my_range_function(star_value, end_value, length=6)
print my_range
[-7.50,-5.98,-4.46,-2.94,-1.42,0.10]
This is essentially equivalent to the R function seq
which can specify a sequence of a given length. Is this possible in Python?
Thanks.
© Stack Overflow or respective owner