Skip to content

Instantly share code, notes, and snippets.

@pgtwitter
Last active July 21, 2024 06:39
Show Gist options
  • Save pgtwitter/d186e445ff27fe0905747dc428889947 to your computer and use it in GitHub Desktop.
Save pgtwitter/d186e445ff27fe0905747dc428889947 to your computer and use it in GitHub Desktop.
半径0.5の外接円を持つ正n角形の周の長さ
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"df = pd.DataFrame([(n, n * np.sin(np.pi/n)) for n in range(3, 100)], columns=['n', '半径0.5の外接円を持つ正n角形の周の長さ'])\n",
"indices = df[df['半径0.5の外接円を持つ正n角形の周の長さ'] > 3].index\n",
"df.loc[indices-2].head(3)"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>n</th>\n",
" <th>半径0.5の外接円を持つ正n角形の周の長さ</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>5</td>\n",
" <td>2.938926</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>6</td>\n",
" <td>3.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>7</td>\n",
" <td>3.037186</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" n 半径0.5の外接円を持つ正n角形の周の長さ\n",
"2 5 2.938926\n",
"3 6 3.000000\n",
"4 7 3.037186"
]
},
"metadata": {},
"execution_count": 1
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 2,
"source": [
"indices = df[df['半径0.5の外接円を持つ正n角形の周の長さ'] > 3.14].index\n",
"df.loc[indices-1].head(3)"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>n</th>\n",
" <th>半径0.5の外接円を持つ正n角形の周の長さ</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>53</th>\n",
" <td>56</td>\n",
" <td>3.139945</td>\n",
" </tr>\n",
" <tr>\n",
" <th>54</th>\n",
" <td>57</td>\n",
" <td>3.140002</td>\n",
" </tr>\n",
" <tr>\n",
" <th>55</th>\n",
" <td>58</td>\n",
" <td>3.140057</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" n 半径0.5の外接円を持つ正n角形の周の長さ\n",
"53 56 3.139945\n",
"54 57 3.140002\n",
"55 58 3.140057"
]
},
"metadata": {},
"execution_count": 2
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 3,
"source": [
"indices = df[df['半径0.5の外接円を持つ正n角形の周の長さ'] > 3.141].index\n",
"df.loc[indices-1].head(3)"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>n</th>\n",
" <th>半径0.5の外接円を持つ正n角形の周の長さ</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>90</th>\n",
" <td>93</td>\n",
" <td>3.140995</td>\n",
" </tr>\n",
" <tr>\n",
" <th>91</th>\n",
" <td>94</td>\n",
" <td>3.141008</td>\n",
" </tr>\n",
" <tr>\n",
" <th>92</th>\n",
" <td>95</td>\n",
" <td>3.141020</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" n 半径0.5の外接円を持つ正n角形の周の長さ\n",
"90 93 3.140995\n",
"91 94 3.141008\n",
"92 95 3.141020"
]
},
"metadata": {},
"execution_count": 3
}
],
"metadata": {}
}
],
"nbformat": 4,
"nbformat_minor": 2,
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": 3
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment