list of range of floats

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    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(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

  • Dale Strickland-Clark

    #2
    Re: list of range of floats

    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.

    Comment

    • Simon Brunning

      #3
      Re: list of range of floats

      On 2/14/07, Steve <samckain@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
      simon@brunningo nline.net

      Comment

      • Steve

        #4
        Re: list of range of floats

        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

        Comment

        • Matimus

          #5
          Re: list of range of floats

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

          Another way of writing that:

          flts = map(float,range (10))

          Comment

          • Larry Bates

            #6
            Re: list of range of floats

            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

            Comment

            • jay.dow@gmail.com

              #7
              Re: list of range of floats

              a = 0.0
              b = 10.0
              inc = .2
              flts = []
              while a < b:
              flts.append(a)
              a += inc


              Comment

              • Steve

                #8
                Re: list of range of floats

                On Wed, 14 Feb 2007 17:29:26 +0000, Simon Brunning wrote:
                On 2/14/07, Steve <samckain@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

                Comment

                • Simon Brunning

                  #9
                  Re: list of range of floats

                  On 2/14/07, Steve <samckain@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
                  simon@brunningo nline.net

                  Comment

                  • Steve

                    #10
                    Re: list of range of floats

                    On Wed, 14 Feb 2007 18:46:34 +0000, Simon Brunning wrote:
                    On 2/14/07, Steve <samckain@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

                    Comment

                    • Bart Ogryczak

                      #11
                      Re: list of range of floats

                      On Feb 14, 6:12 pm, Steve <samck...@south slope.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))



                      Comment

                      • Steve

                        #12
                        Re: list of range of floats

                        On Thu, 15 Feb 2007 05:57:45 -0800, Bart Ogryczak wrote:
                        On Feb 14, 6:12 pm, Steve <samck...@south slope.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

                        Comment

                        Working...