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(f lts)
When I run it I get the following DeprecationWarn ing: integer argument
expected, got float. How can I store a list of floats?
TIA
Steve 11 18555
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(f lts)
When I run it I get the following DeprecationWarn ing: 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.
On 2/14/07, Steve <sa******@south slope.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(f lts)
When I run it I get the following DeprecationWarn ing: 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***@brunningo nline.net http://www.brunningonline.net/simon/blog/
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 DeprecationWarn ing: 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
fits = list(float(a) for a in range(0, 10))
Another way of writing that:
flts = map(float,range (10))
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(f lts)
When I run it I get the following DeprecationWarn ing: 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
a = 0.0
b = 10.0
inc = .2
flts = []
while a < b:
flts.append(a)
a += inc
On Wed, 14 Feb 2007 17:29:26 +0000, Simon Brunning wrote:
On 2/14/07, Steve <sa******@south slope.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 DeprecationWarn ing: 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
On 2/14/07, Steve <sa******@south slope.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***@brunningo nline.net http://www.brunningonline.net/simon/blog/
On Wed, 14 Feb 2007 18:46:34 +0000, Simon Brunning wrote:
On 2/14/07, Steve <sa******@south slope.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 insertData(self,data):
# Start off with an array of the desired size
# "self.MEASURED", etc., are integers
arrayData = zeros(, Float64)
|
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);
}
|
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 there isn't a way.
|
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 to do this in C++? Something like:
int list = { x + 1 for (int x = 0; x < 5; x++); }
Or something?
|
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 counter
within the loop declaration, for loops have always seemed to me to be
about doing something a certain number of times, and not about iterating
over an object.
The reason for this distinction comes from the fact that I read a lot
how...
| |
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 in inputs:
totalProp+=each
print "totalProp=",totalProp
|
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 Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY...
|
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 chance to be approved ?
|
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 = list(range(50,100, 2))
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |