[PYTHON] Is there a secret to the frequency of pi numbers?

【Overview】

I checked the frequency of numbers that appear in pi. I also checked the number of Napiers. The target is after the decimal point.

[Preparation]

-Obtain the API key from Plotly to use the Python library Plotly. (Not required if you do not draw a graph) ・ Pi and Number of Napiers Copy and paste the numbers after the decimal point into the text from /e.5mil). (Note that the number of Napiers is filled with 0 because the first line has a different digit from the other lines.)

[Folder structure]

|---scripts | --- pi.py (Check the frequency of pi numbers) | --- pi_graph.py (Create a bar graph of pi) | --- pi.txt (Pi after the decimal point) | --- e.py (Check the frequency of Napier numbers) | --- e_graph.py (Create bar graph of Napier number) | --- e.txt (number of napiers after the decimal point)

[Program and results]

To display the graph https://plot.ly/~ユーザ名/0/#plot You can see it by accessing.

pi.py


# -*- coding: utf-8 -*-

zero = 0
one = 0
two = 0
three = 0
four = 0
five = 0
six = 0
seven = 0
eight = 0
nine = 0

for line in open('pi.txt', 'r'):
    for i in xrange(100):
        if(line[i] == '0'):
            zero += 1
        elif(line[i] == '1'):
            one += 1
        elif(line[i] == '2'):
            two += 1
        elif(line[i] == '3'):
            three += 1
        elif(line[i] == '4'):
            four += 1
        elif(line[i] == '5'):
            five += 1
        elif(line[i] == '6'):
            six += 1
        elif(line[i] == '7'):
            seven += 1
        elif(line[i] == '8'):
            eight += 1
        elif(line[i] == '9'):
            nine += 1
print zero    #99959
print one     #99758
print two     #100026
print three   #100229
print four    #100230
print five    #100359
print six     #99548
print seven   #99800
print eight   #99985
print nine    #100106

e.py


# -*- coding: utf-8 -*-

zero = -3 #I've filled the first line of text with three zeros, so I'll reduce it.
one = 0
two = 0
three = 0
four = 0
five = 0
six = 0
seven = 0
eight = 0
nine = 0

for line in open('e.txt', 'r'):
    for i in xrange(60):
        if(line[i] == '0'):
            zero += 1
        elif(line[i] == '1'):
            one += 1
        elif(line[i] == '2'):
            two += 1
        elif(line[i] == '3'):
            three += 1
        elif(line[i] == '4'):
            four += 1
        elif(line[i] == '5'):
            five += 1
        elif(line[i] == '6'):
            six += 1
        elif(line[i] == '7'):
            seven += 1
        elif(line[i] == '8'):
            eight += 1
        elif(line[i] == '9'):
            nine += 1
print zero    #498642
print one     #500511
print two     #499302
print three   #501715
print four    #500420
print five    #500489
print six     #499875
print seven   #500015
print eight   #499078
print nine    #500290

pi_graph.py


# -*- coding: utf-8 -*-

import plotly
import plotly.plotly as py
import plotly.graph_objs as go 
plotly.tools.set_credentials_file(username='User name', api_key='API key')

data = [go.Bar(
            x=['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'],
            y=[99959, 99758, 100026, 100229, 100230, 100359, 99548, 99800, 99985, 100106]
    )]

py.iplot(data, filename='basic-bar')
pi.png

e_graph.py


# -*- coding: utf-8 -*-

import plotly
import plotly.plotly as py
import plotly.graph_objs as go 
plotly.tools.set_credentials_file(username='User name', api_key='API key')

data = [go.Bar(
            x=['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'],
            y=[498642, 500511, 499302, 501715, 500420, 500489, 499875, 500015, 499078, 500290]
    )]

py.iplot(data, filename='basic-bar')
e.png

[Discussion]

It seems that both the pi and the number of Napiers appear at the same frequency ... Is there a mathematical theorem that already appears at the same frequency? (If you know it, please let me know in the comments)

[Reference site]

https://plot.ly/python/bar-charts/

Recommended Posts

Is there a secret to the frequency of pi numbers?
Is there a bias in the numbers that appear in the Fibonacci numbers?
[python] [meta] Is the type of python a type?
How to calculate the volatility of a brand
FAQ: Why is the comparison of numbers inconsistent?
How to make a Raspberry Pi that speaks the tweets of the specified user
Convert a slice object to a list of index numbers
A memo to visually understand the axis of pandas.Panel
Steps to calculate the likelihood of a normal distribution
Zip 4 Gbyte problem is a story of the past
What is a recommend engine? Summary of the types
Python Note: The mystery of assigning a variable to a variable
When a file is placed in the shared folder of Raspberry Pi, the process is executed.
How to check in Python if one of the elements of a list is in another list
[Ubuntu] How to delete the entire contents of a directory
I thought a little because the Trace Plot of the stan parameter is hard to see.
Make a note of what you want to do in the future with Raspberry Pi
I made a function to check the model of DCGAN
How to quickly count the frequency of appearance of characters from a character string in Python?
When a character string of a certain series is in the Key of the dictionary, the character string is converted to the Value of the dictionary.
The image is a slug
Is the lottery profitable? ~ LOTO7 and the law of large numbers ~
How to connect the contents of a list into a string
I sent the data of Raspberry Pi to GCP (free)
What to do when a part of the background image becomes transparent when the transparent image is combined with Pillow
A story that is a little addicted to the authority of the directory specified by expdp (for beginners)
It is surprisingly troublesome to get a list of the last login date and time of Workspaces
Python will fail if there is a space after the backslash
[Blender] Script to check if the selected one is a mesh
How to determine the existence of a selenium element in Python
Unfortunately there is no sense of unity in the where method
March 14th is Pi Day. The story of calculating pi with python
I tried to automate the watering of the planter with Raspberry Pi
A story that struggled to handle the Python package of PocketSphinx
Conditional branch due to the existence of a shell script file
How easy is it to synthesize a drug on the market?
How to check the memory size of a variable in Python
On Linux, the time stamp of a file is a little past.
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
I tried to create a list of prime numbers with python
[Go] Create a CLI command to change the extension of the image
How to check the memory size of a dictionary in Python
How to find the memory address of a Pandas dataframe value
How to output the output result of the Linux man command to a file
[Python3] Define a decorator to measure the execution time of a function
How to get the vertex coordinates of a feature in ArcPy
A command to easily check the speed of the network on the console
Raspberry Pi --1 --First time (Connect a temperature sensor to display the temperature)
The road to web application development is a long way off
Create a function to get the contents of the database in Go
[NNabla] How to remove the middle tier of a pre-built network
[Python] A simple function to find the center coordinates of a circle
[Python] A program that rotates the contents of the list to the left
Is there a special in scipy? ??
Raspberry Pi? What's that? Level of hardware Inexperienced college students created a system to grasp if there are people in the office
Science "Is Saito the representative of Saito?"
Supplement to the explanation of vscode
The story of writing a program
[Python] Change the alphabet to numbers
Let's use Python to represent the frequency of binary data contained in a data frame in a single bar graph.
Check the number of prime numbers less than or equal to n