473,327 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

list of range of floats

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
11 18496
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
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
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
fits = list(float(a) for a in range(0, 10))

Another way of writing that:

flts = map(float,range(10))

Feb 14 '07 #5
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
a = 0.0
b = 10.0
inc = .2
flts = []
while a < b:
flts.append(a)
a += inc
Feb 14 '07 #7
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stephen Boulet | last post by:
I have a long list of floats (1613808 elements long). It takes quite a while to load this into a 7 dimensional Numeric array. Is there any obvious way to speed this up? def...
15
by: Xah Lee | last post by:
Here's the belated Java solution. import java.util.List; import java.util.ArrayList; import java.lang.Math; class math { public static List range(double n) { return range(1,n,1); }
8
by: Madhusudan Singh | last post by:
Is it possible to convert a very long list of strings to a list of floats in a single statement ? I have tried float(x) and float(x) but neither work. I guess I would have to write a loop if...
5
by: Chris | last post by:
Hey all. Anyone who is familiar with Python programming knows that you can have code like this: list = This code puts all the items processed by the for loop in a list plus 1. Is there a way...
17
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
9
by: joanne matthews (RRes-Roth) | last post by:
I'm getting different results when I add up a list of floats depending on the order that I list the floats. For example, the following returns False: def check(): totalProp=0 inputs= for each...
0
by: DarrenWeber | last post by:
# Copyright (C) 2007 Darren Lee Weber # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free...
4
by: Michal Bozon | last post by:
many Python newcomers are confused why range(10), does not include 10. If there was a proposal for the new syntax for ranges, which is known e.g. from Pascal or Ruby... ....is there a...
5
by: globalrev | last post by:
if i want a list with all numbers between x and y is there a way to do this with an inbult function. i mean i can always construct a function to do this but is there soemthing like: nbrs =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.