473,320 Members | 1,950 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,320 software developers and data experts.

to calculate the universal distribution of continued fraction expansion

2
Hi all,

I'm studying python program in uni.
my lecture asks us to calculate the universal distribution of continued fraction expansion

But I always have an error says: TypeError: 'builtin_function_or_method' object is not subscriptable.
here's my algorithm:

Expand|Select|Wrap|Line Numbers
  1. def universal_distro(N=10000):
  2.         import random
  3.     x = random.random()
  4.     g = list()
  5.     m = dict()
  6.     o = dict()
  7.     N = len(o)
  8.     while N < 10000:
  9.         for x in range[0,1]:
  10.             w = number2cfe(x,N=15)
  11.             e = w[n]
  12.             if n < 15:
  13.                 count = 0
  14.                 if w[n] not in g:
  15.                     for e in w:
  16.                         if e == w[n]:
  17.                             count += 1
  18.                     g.append(w[n])
  19.                 n += 1
  20.                 m[w[n]] = count
  21.         for k in m.keys():
  22.             if o.has_key(k):
  23.                 o[k] += m[k]
  24.             else:
  25.                 o[k] = m[k]
  26.         N += 1
  27.     return o
  28.  
  29. >>> universal_distro(10000)
  30. File "<pyshell#120>", line 9, in universal_distro
  31.     for x in range[0,1]:
  32. TypeError: 'builtin_function_or_method' object is not subscriptable
  33.  
Can someone help me out?
thanks
Sep 3 '11 #1
3 2580
ohh I think your syntax is incorrect for the Range()

try using ( instead of [
Sep 3 '11 #2
pyask
2
Hi I want to calculate the distribution of continued fraction expansion (of N up to 10000). I think I need to choose a random variable x and calculate its cfe for n = 15, then store the counts in a dictionary. Then, choose another random variable x and continue the calculation until the size of the dictionary reaches 10000.

But I just can't let my program understand this idea.
Sep 4 '11 #3
dwblas
626 Expert 512MB
You don't use the random numbers anywhere? Explain in more detail what you want to do (the single letter variable names give me no clue). Also, you now have "x" defined twice
Expand|Select|Wrap|Line Numbers
  1.     x = random.random()
  2. #
  3. # and --> note that this is a bogus statement as it will only execute once
  4.         for x in range[0,1]:  # should be range(0, 1)
  5. #
  6. # perhaps you want something more like
  7. import random
  8. for x in xrange(0, 10): ## but you would use while len(a_dict) < 10000:
  9.     print random.random() 
Sep 4 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Damian H | last post by:
Hi, For some magical reason, my database replication has suddenly stopped working. I modified the publication but the Distribution agent will not run; the snapshot does not get applied to the...
0
by: Nick Kew | last post by:
Rationale ========= Many applications today benefit from an SGML and/or XML Entity Catalogue to dereference entities referenced by a Public Identifier. For a validating SGML parser this is an...
5
by: Koen | last post by:
Hi, I am looking for an algorithm that figures out which numbers from a given set add up to another number. I am sure this has been done before, but I have no idea how such a calculation is...
24
by: Raven | last post by:
Hi to all, I need to calculate the hpergeometric distribution: choose(r, x) * choose(b, n-x) p(x; r,b,n) = ----------------------------- choose(r+b, n) choose(r,x) is the binomial...
22
by: dos.fishing | last post by:
Hello, I'm writing a function that should do the following: /** * Calculate and return fraction of valueA where max fractions is 31. * param valueA A five bit value, 0-31. * param valueB The...
0
by: hutchijw | last post by:
Im currently in the process of creating a tool that will assist us in making distribution lists. When we create a distribution list manually, we assign an owner in the manage by tab, and to delegate...
2
by: frozenfirefly | last post by:
okay, so the first class of this program is the Fraction class. and which I supposed to create: 1. method to input numerator & denominator of fraction 2. and a method to reduce the fraction to its...
0
by: eGenix Team: M.-A. Lemburg | last post by:
________________________________________________________________________ ANNOUNCING eGenix.com mx Base Distribution Version 3.1.1 for Python 2.6 Open Source Python extensions providing...
0
by: M.-A. Lemburg | last post by:
Just to let you know: we also provide binaries and support for Mac OS X Intel and PPC. Thanks to Joe Strout for pinging us about this. On 2008-10-15 17:41, eGenix Team: M.-A. Lemburg wrote: ...
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
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.