By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,012 Members | 988 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,012 IT Pros & Developers. It's quick & easy.

list of range of floats

P: n/a
I'm trying to create a list range of floats and running into problems.
I've been trying something like:

a = 0.0
b = 10.0

flts = range(a, b)

fltlst.append(flts)

When I run it I get the following DeprecationWarning: integer argument
expected, got float. How can I store a list of floats?

TIA
Steve

Feb 14 '07 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Steve wrote:
I'm trying to create a list range of floats and running into problems.
I've been trying something like:

a = 0.0
b = 10.0

flts = range(a, b)

fltlst.append(flts)

When I run it I get the following DeprecationWarning: integer argument
expected, got float. How can I store a list of floats?

TIA
Steve
range only does ints. If you want floats, you'll have to write your own
version.

Feb 14 '07 #2

P: n/a
On 2/14/07, Steve <sa******@southslope.netwrote:
I'm trying to create a list range of floats and running into problems.
I've been trying something like:

a = 0.0
b = 10.0

flts = range(a, b)

fltlst.append(flts)

When I run it I get the following DeprecationWarning: integer argument
expected, got float. How can I store a list of floats?
There would be an *enormous* number of floats between zero and ten. Do
you really want all of them in your list? I hope you have a few
terrabytes of RAM...

Or do you just want the integer values as floats?

fits = list(float(a) for a in range(0, 10))

--
Cheers,
Simon B
si***@brunningonline.net
http://www.brunningonline.net/simon/blog/
Feb 14 '07 #3

P: n/a
On Wed, 14 Feb 2007 17:27:06 +0000, Dale Strickland-Clark wrote:
Steve wrote:
>I'm trying to create a list range of floats and running into problems.
I've been trying something like:

a = 0.0
b = 10.0

flts = range(a, b)

fltlst.append(flts)

When I run it I get the following DeprecationWarning: integer argument
expected, got float. How can I store a list of floats?

TIA
Steve

range only does ints. If you want floats, you'll have to write your own
version.
I was afraid of that. Thanks for the quick reply.

Steve

Feb 14 '07 #4

P: n/a
fits = list(float(a) for a in range(0, 10))

Another way of writing that:

flts = map(float,range(10))

Feb 14 '07 #5

P: n/a
Steve wrote:
I'm trying to create a list range of floats and running into problems.
I've been trying something like:

a = 0.0
b = 10.0

flts = range(a, b)

fltlst.append(flts)

When I run it I get the following DeprecationWarning: integer argument
expected, got float. How can I store a list of floats?

TIA
Steve
What does range of floats mean? How many floats are there
between 0.0 and 10.0? If you want the step to be 1.0
and beginning and ending values will be whole numbers then
this will work:

flts=[float(i) for i in range(1, 11)]

If you want arbitrary starting and ending floats and an
arbitrary step, you will need to write your own function.

-Larry
Feb 14 '07 #6

P: n/a
a = 0.0
b = 10.0
inc = .2
flts = []
while a < b:
flts.append(a)
a += inc
Feb 14 '07 #7

P: n/a
On Wed, 14 Feb 2007 17:29:26 +0000, Simon Brunning wrote:
On 2/14/07, Steve <sa******@southslope.netwrote:
>I'm trying to create a list range of floats and running into problems.
I've been trying something like:

a = 0.0
b = 10.0

flts = range(a, b)

fltlst.append(flts)

When I run it I get the following DeprecationWarning: integer argument
expected, got float. How can I store a list of floats?

There would be an *enormous* number of floats between zero and ten. Do
you really want all of them in your list? I hope you have a few
terrabytes of RAM...

Or do you just want the integer values as floats?

fits = list(float(a) for a in range(0, 10))
After re-reading my original post I was pretty vague. I'm trying to creat
a list of ranges of floats, 0.0 10.0, 11 20, etc then checking to see if
an float, example 12.5 falls in the list and if so get the list index of
where it is in the index. Does this make sense?

Steve
Feb 14 '07 #8

P: n/a
On 2/14/07, Steve <sa******@southslope.netwrote:
After re-reading my original post I was pretty vague. I'm trying to creat
a list of ranges of floats, 0.0 10.0, 11 20, etc then checking to see if
an float, example 12.5 falls in the list and if so get the list index of
where it is in the index. Does this make sense?
Ah, you want to know if a certain number is between to other numbers.
That's not what range() is for - range() is for generating lists of
integers. You can use it to do a between test for integers, I suppose,
but even for integers it's a pretty poor way of going about it -
you'll be creating a potentially large lists of integers, only to
throw it away again.

Consider something like:

def between(lower, upper, target):
return lower < target < upper

Works for integers and floats interchangably. Or better still, do the
lower < target < upper thing inline.

--
Cheers,
Simon B
si***@brunningonline.net
http://www.brunningonline.net/simon/blog/
Feb 14 '07 #9

P: n/a
On Wed, 14 Feb 2007 18:46:34 +0000, Simon Brunning wrote:
On 2/14/07, Steve <sa******@southslope.netwrote:
>After re-reading my original post I was pretty vague. I'm trying to creat
a list of ranges of floats, 0.0 10.0, 11 20, etc then checking to see if
an float, example 12.5 falls in the list and if so get the list index of
where it is in the index. Does this make sense?

Ah, you want to know if a certain number is between to other numbers.
That's not what range() is for - range() is for generating lists of
integers. You can use it to do a between test for integers, I suppose,
but even for integers it's a pretty poor way of going about it -
you'll be creating a potentially large lists of integers, only to
throw it away again.

Consider something like:

def between(lower, upper, target):
return lower < target < upper

Works for integers and floats interchangably. Or better still, do the
lower < target < upper thing inline.
You hit it on the head Simon. Thanks for strightening out my thinking.

Steve

Feb 15 '07 #10

P: n/a
On Feb 14, 6:12 pm, Steve <samck...@southslope.netwrote:
I'm trying to create a list range of floats and running into problems.
I've tried it the easy way. Works.
map(float,range(a,b))

Feb 15 '07 #11

P: n/a
On Thu, 15 Feb 2007 05:57:45 -0800, Bart Ogryczak wrote:
On Feb 14, 6:12 pm, Steve <samck...@southslope.netwrote:
>I'm trying to create a list range of floats and running into problems.

I've tried it the easy way. Works.
map(float,range(a,b))
Thanks Bart, I'll give it a try

Steve

Feb 15 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.