Spaces:
Build error
Build error
Download pi_utils.py from Dhruv1102/PLAY_WITH_PI: direct link, hf CLI and curl.
- Browser
- Download file 682 Bytes
-
https://huggingface.co/spaces/Dhruv1102/PLAY_WITH_PI/resolve/main/pi_utils.py
- Command line
-
hf download hf://spaces/Dhruv1102/PLAY_WITH_PI/pi_utils.py
-
curl -L -o pi_utils.py https://huggingface.co/spaces/Dhruv1102/PLAY_WITH_PI/resolve/main/pi_utils.py
682 Bytes
| import random | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| pi_facts = [ | |
| "π is irrational and never ends!", | |
| "π has been calculated to over 62 trillion digits!", | |
| "The symbol π was first used in 1706.", | |
| "You can’t express π as a fraction!", | |
| "March 14 (3/14) is Pi Day!" | |
| ] | |
| def random_pi_fact(): | |
| return random.choice(pi_facts) | |
| def generate_pi_graph(): | |
| digits = [int(d) for d in open('pi_digits.txt').read() if d.isdigit()] | |
| x = list(range(len(digits))) | |
| y = np.cumsum([(-1)**i * d for i, d in enumerate(digits[:500])]) | |
| fig, ax = plt.subplots() | |
| ax.plot(x[:len(y)], y) | |
| ax.set_title("π Waveform based on Digits") | |
| return fig | |