Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions SaeWatanabe/.ipynb_checkpoints/Untitled-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n"
]
}
],
"source": [
"# 課題1\n",
"answer1 = list(range(1,11))\n",
"print(answer1)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2, 4, 6, 8, 10]\n"
]
}
],
"source": [
"# 課題2\n",
"answer2 = [i for i in answer1 if i%2 == 0]\n",
"print(answer2)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f'}\n"
]
}
],
"source": [
"# 課題3\n",
"list1 = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"]\n",
"answer3 = {i:list1[i] for i in range(len(list1))}\n",
"print(answer3)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"インクリメント前\n",
"山田 ... 名前:山田 年齢:23歳 性別:男 身長:170.3cm 体重:60.2kg\n",
"高橋 ... 名前:高橋 年齢:30歳 性別:女 身長:165.2cm 体重:46.2kg\n",
"\n",
"インクリメント後\n",
"山田 ... 名前:山田 年齢:24歳 性別:男 身長:170.3cm 体重:60.2kg\n",
"高橋 ... 名前:高橋 年齢:30歳 性別:女 身長:165.2cm 体重:46.2kg\n",
"\n",
"Humanクラスのインスタンスカウント ... 2\n"
]
}
],
"source": [
"# 課題4\n",
"class Human:\n",
" \n",
" # インスタンスのカウント\n",
" cnt = 0\n",
" \n",
" # コンストラクタでデータを初期化 \n",
" def __init__ (self,name,age,sex,height,weight):\n",
" \n",
" # インスタンスをカウントアップ\n",
" Human.cnt += 1\n",
" \n",
" # データの初期化\n",
" self.name = name\n",
" self.age = age\n",
" self.sex = sex\n",
" self.height = height\n",
" self.weight = weight\n",
" \n",
" # 年齢をインクリメント\n",
" def countup_age(self):\n",
" self.age += 1\n",
" \n",
" # クラスメソッドを作成\n",
" @classmethod\n",
" def class_count(cls):\n",
" return cls.cnt\n",
" \n",
" # 文字列を返す\n",
" def __repr__(self):\n",
" return \"名前:%s 年齢:%d歳 性別:%s 身長:%.1fcm 体重:%.1fkg\"%(self.name,self.age,self.sex,self.height,self.weight)\n",
" \n",
" \n",
"# インスタンスを作成 \n",
"yamada = Human(name=\"山田\", age=23, sex=\"男\", height=170.3, weight=60.2)\n",
"takahashi = Human(name=\"高橋\", age=30, sex=\"女\", height=165.2, weight=46.2)\n",
"\n",
"print(\"インクリメント前\")\n",
"print(\"山田 ... %s\"%yamada)\n",
"print(\"高橋 ... %s\"%takahashi)\n",
"print()\n",
"\n",
"# 山田の年齢をインクリメント\n",
"yamada.countup_age()\n",
"\n",
"print(\"インクリメント後\")\n",
"print(\"山田 ... %s\"%yamada)\n",
"print(\"高橋 ... %s\"%takahashi)\n",
"print()\n",
"\n",
"print(\"Humanクラスのインスタンスカウント ... %d\"%Human.class_count())\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
222 changes: 222 additions & 0 deletions SaeWatanabe/.ipynb_checkpoints/answer-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n"
]
}
],
"source": [
"# 課題1\n",
"answer1 = list(range(1,11))\n",
"print(answer1)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2, 4, 6, 8, 10]\n"
]
}
],
"source": [
"# 課題2\n",
"answer2 = [i for i in answer1 if i%2 == 0]\n",
"print(answer2)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f'}\n"
]
}
],
"source": [
"# 課題3\n",
"list1 = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"]\n",
"answer3 = {i:list1[i] for i in range(len(list1))}\n",
"print(answer3)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"インクリメント前\n",
"山田 ... 名前:山田 年齢:23歳 性別:男 身長:170.3cm 体重:60.2kg\n",
"高橋 ... 名前:高橋 年齢:30歳 性別:女 身長:165.2cm 体重:46.2kg\n",
"\n",
"インクリメント後\n",
"山田 ... 名前:山田 年齢:24歳 性別:男 身長:170.3cm 体重:60.2kg\n",
"高橋 ... 名前:高橋 年齢:30歳 性別:女 身長:165.2cm 体重:46.2kg\n",
"\n",
"Humanクラスのインスタンスカウント() = 2\n"
]
}
],
"source": [
"# 課題4\n",
"class Human:\n",
" \n",
" # インスタンスのカウント\n",
" cnt = 0\n",
" \n",
" # コンストラクタでデータを初期化 \n",
" def __init__ (self,name,age,sex,height,weight):\n",
" \n",
" # インスタンスをカウントアップ\n",
" Human.cnt += 1\n",
" \n",
" # データの初期化\n",
" self.name = name\n",
" self.age = age\n",
" self.sex = sex\n",
" self.height = height\n",
" self.weight = weight\n",
" \n",
" # 年齢をインクリメント\n",
" def countup_age(self):\n",
" self.age += 1\n",
" \n",
" # クラスメソッドを作成\n",
" @classmethod\n",
" def class_count(cls):\n",
" return cls.cnt\n",
" \n",
" # 文字列を返す\n",
" def __repr__(self):\n",
" return \"名前:%s 年齢:%d歳 性別:%s 身長:%.1fcm 体重:%.1fkg\"%(self.name,self.age,self.sex,self.height,self.weight)\n",
" \n",
" \n",
"# インスタンスを作成 \n",
"yamada = Human(name=\"山田\", age=23, sex=\"男\", height=170.3, weight=60.2)\n",
"takahashi = Human(name=\"高橋\", age=30, sex=\"女\", height=165.2, weight=46.2)\n",
"\n",
"print(\"インクリメント前\")\n",
"print(\"山田 ... %s\"%yamada)\n",
"print(\"高橋 ... %s\"%takahashi)\n",
"print()\n",
"\n",
"# 山田の年齢をインクリメント\n",
"yamada.countup_age()\n",
"\n",
"print(\"インクリメント後\")\n",
"print(\"山田 ... %s\"%yamada)\n",
"print(\"高橋 ... %s\"%takahashi)\n",
"print()\n",
"\n",
"\n",
"print(\"Humanクラスのインスタンスカウント() = %d\"%Human.class_count())"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[13 16]\n",
" [29 36]]\n"
]
}
],
"source": [
"# 課題5\n",
"import numpy as np\n",
"\n",
"# 行列の初期化\n",
"x = np.array([[1.,2.],[3.,4.]])\n",
"y = np.array([[3.,4.],[5.,6.]])\n",
"\n",
"print(x.dot(y))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"3.2659863237109041"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 課題6\n",
"# 行列の初期化\n",
"X = np.array([1.,2.,3.])\n",
"Y = np.array([0.,1.,2.])\n",
"\n",
"# cosを計算\n",
"X.dot(Y) / np.linalg.norm(x) * np.linalg.norm(Y)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading