diff --git a/Inoue/README.md b/Inoue/README.md new file mode 100644 index 0000000..31ad9bf --- /dev/null +++ b/Inoue/README.md @@ -0,0 +1,5 @@ +–¼‘OFˆäã‘å‹P +‘åŠwF“Œ‹ž‘åŠw +êUF–ò‰ÈŠwêU +ŠJ”­ŒoŒ±F‚È‚µ +’†Šú“I‚È–Ú•WFAI‰æ‘œf’f‹Zp‚̎擾 diff --git "a/Inoue/\350\252\262\351\241\214.ipynb" "b/Inoue/\350\252\262\351\241\214.ipynb" new file mode 100644 index 0000000..e876949 --- /dev/null +++ "b/Inoue/\350\252\262\351\241\214.ipynb" @@ -0,0 +1,335 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class CLASS:\n", + " def __init__ (self):\n", + " self.list1 = [30, \"inoue\", False]\n", + " self.list2 = [22, \"yanagi\", True]\n", + " self.list3 = [18, \"tachibana\", True]\n", + " self.list4 = [24, \"hayashi\", False]\n", + " ã“ã®ã¨ãlistã®é•·ã•ã¯ã™ã¹ã¦\n", + " for i in range(len(list1))\n", + " age, name, gakushin = list1[i], list2[i], list3[i]\n", + " \n", + " pass\n", + "\n", + " def average(self)\n", + " \n", + "taisha = CLASS([å¹´é½¢ã®ãƒªã‚¹ãƒˆ], [åå‰ã®ãƒªã‚¹ãƒˆ], [True Falseã®å­¦æŒ¯æœ‰ç„¡ãƒªã‚¹ãƒˆ])\n", + "\n", + "\n", + "taisha.gakushin()\n", + "#学振をæŒã£ã¦ã„る人ã®åå‰ã‚’表示ã™ã‚‹\n", + "taisha.average()\n", + "#å¹´é½¢ã®å¹³å‡å€¤\n", + "\n", + "\n", + "\n", + "複åˆçš„ã«ã‚„ã‚‹ã«ã¯\n", + "class Person:\n", + " def __init__ (self, name, age, gakushin):\n", + " self\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[30, 'inoue', False], [22, 'yanagi', True], [18, 'tachibana', True], [24, 'hayashi', False]]\n", + "[[30, 22, 18, 24], ['inoue', 'yanagi', 'tachibana', 'hayashi'], [False, True, True, False]]\n", + "代è¬ã®å­¦ç”Ÿã®å¹³å‡å¹´é½¢ã¯ 23.5 ã§ã™ã€‚\n", + "学振有: yanagi\n", + "学振有: tachibana\n", + "学振無: inoue\n", + "学振無: hayashi\n" + ] + } + ], + "source": [ + "#複数ã®ãƒªã‚¹ãƒˆã‚’一ã¤ã«ã¾ã¨ã‚ã‚‹\n", + "list1 = [30, \"inoue\", False]\n", + "list2 = [22, \"yanagi\", True]\n", + "list3 = [18, \"tachibana\", True]\n", + "list4 = [24, \"hayashi\", False]\n", + "list_individual = [list1, list2, list3, list4]\n", + "list_item = [[], [], []]\n", + "for i in range(3):\n", + " for j in range(len(list_individual)):\n", + " list_item[i].append(list_individual[j][i])\n", + "print(list_individual)\n", + "print(list_item)\n", + " \n", + " \n", + "#å¹´é½¢ã®å¹³å‡ç‚¹ã‚’計算ã™ã‚‹\n", + "sum = 0\n", + "for k in range(len(list_individual)):\n", + " sum = sum + list_item[0][k]\n", + "age_average = sum / len(list_individual)\n", + "print(\"代è¬ã®å­¦ç”Ÿã®å¹³å‡å¹´é½¢ã¯\", age_average, \"ã§ã™ã€‚\")\n", + "\n", + " \n", + "#å­¦æŒ¯ã®æœ‰ç„¡ã‚’判断ã™ã‚‹\n", + "gakushin = []\n", + "no_gakushin = []\n", + "for l in range(len(list_individual)):\n", + " if list_item[2][l] == True:\n", + " gakushin.append(list_item[1][l])\n", + " else:\n", + " no_gakushin.append(list_item[1][l])\n", + "for m in gakushin:\n", + " print(\"学振有:\", m)\n", + "for n in no_gakushin:\n", + " print(\"学振無:\", n)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "TypeError", + "evalue": "gakushin_person() missing 1 required positional argument: 'self'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"学振無:\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 36\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 37\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mTaisha\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgakushin_person\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: gakushin_person() missing 1 required positional argument: 'self'" + ] + } + ], + "source": [ + "class Taisha:\n", + " \n", + " #複数ã®ãƒªã‚¹ãƒˆã‚’一ã¤ã«ã¾ã¨ã‚ã‚‹\n", + " def __init__(self):\n", + " self.list1 = [30, \"inoue\", False]\n", + " self.list2 = [22, \"yanagi\", True]\n", + " self.list3 = [18, \"tachibana\", True]\n", + " self.list4 = [24, \"hayashi\", False]\n", + " self.list_individual = [self.list1, self.list2, self.list3, self.list4]\n", + " self.list_item = [[], [], []]\n", + " for i in range(len(self.list_item)):\n", + " for j in range(len(self.list_individual)):\n", + " self.list_item[i].append(self.list_individual[j][i])\n", + "\n", + " #å¹´é½¢ã®å¹³å‡ç‚¹ã‚’計算ã™ã‚‹\n", + " def average(self):\n", + " sum = 0\n", + " for k in range(len(self.list_individual)):\n", + " sum = sum + self.list_item[0][k]\n", + " age_average = sum / len(self.list_individual)\n", + " print(\"代è¬ã®å­¦ç”Ÿã®å¹³å‡å¹´é½¢ã¯\", age_average, \"ã§ã™ã€‚\")\n", + "\n", + " #å­¦æŒ¯ã®æœ‰ç„¡ã‚’判断ã™ã‚‹\n", + " def gakushin_person(self):\n", + " gakushin = []\n", + " no_gakushin = []\n", + " for l in range(len(self.list_individual)):\n", + " if self.list_item[2][l] == True:\n", + " gakushin.append(self.list_item[1][l])\n", + " else:\n", + " no_gakushin.append(self.list_item[1][l])\n", + " for m in gakushin:\n", + " print(\"学振有:\", m)\n", + " for n in no_gakushin:\n", + " print(\"学振無:\", n)\n", + "\n", + "print(Taisha.gakushin_person())" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "代è¬ã®å­¦ç”Ÿã®å¹³å‡å¹´é½¢ã¯ 23.5 ã§ã™ã€‚\n", + "学振有: yanagi\n", + "学振有: tachibana\n", + "学振無: inoue\n", + "学振無: hayashi\n", + "['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'abstract', 'age_average', 'average', 'gakushin', 'gakushin_person', 'list_individual', 'list_item', 'no_gakushin']\n", + "\n" + ] + } + ], + "source": [ + "class Taisha:\n", + " '''\n", + " to initialize, list variables are required.\n", + " $ Inoue = Taisha(list1, list2, list3, list4)\n", + " '''\n", + " #複数ã®ãƒªã‚¹ãƒˆã‚’個人ã€é …目別ã«ã¾ã¨ã‚ã‚‹\n", + " def __init__(self, list_1, list_2, list_3, list_4):\n", + " self.list_individual = [list_1, list_2, list_3, list_4]\n", + " self.list_item = [[], [], []]\n", + " for i in range(len(self.list_item)):\n", + " for j in range(len(self.list_individual)):\n", + " self.list_item[i].append(self.list_individual[j][i])\n", + " \n", + " self.gakushin, self.no_gakushin = self.gakushin_person()\n", + " self.age_average = self.average()\n", + " self.abstract()\n", + " \n", + " #å¹´é½¢ã®å¹³å‡ç‚¹ã‚’計算ã™ã‚‹\n", + " def average(self):\n", + " sum = 0\n", + " for k in range(len(self.list_individual)):\n", + " sum = sum + self.list_item[0][k]\n", + " age_average = sum / len(self.list_individual)\n", + " return age_average\n", + " \n", + " #å­¦æŒ¯ã®æœ‰ç„¡ã‚’判断ã™ã‚‹\n", + " def gakushin_person(self):\n", + " gakushin = []\n", + " no_gakushin = []\n", + " for l in range(len(self.list_individual)):\n", + " if self.list_item[2][l] == True:\n", + " gakushin.append(self.list_item[1][l])\n", + " else:\n", + " no_gakushin.append(self.list_item[1][l])\n", + " return gakushin, no_gakushin\n", + "\n", + " #データを表示ã™ã‚‹\n", + " def abstract(self):\n", + " print(\"代è¬ã®å­¦ç”Ÿã®å¹³å‡å¹´é½¢ã¯\", self.age_average, \"ã§ã™ã€‚\")\n", + " for m in self.gakushin:\n", + " print(\"学振有:\", m)\n", + " for n in self.no_gakushin:\n", + " print(\"学振無:\", n)\n", + "\n", + " \n", + "list_1 = [30, \"inoue\", False]\n", + "list_2 = [22, \"yanagi\", True]\n", + "list_3 = [18, \"tachibana\", True]\n", + "list_4 = [24, \"hayashi\", False]\n", + "\n", + "Inoue = Taisha(list_1, list_2, list_3, list_4)\n", + "\n", + "print(dir(Inoue))\n", + "print(type(Inoue))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'Inoue' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdir\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mInoue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mInoue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'Inoue' is not defined" + ] + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "代è¬ã®å­¦ç”Ÿã®å¹³å‡å¹´é½¢ã¯ 23.5 ã§ã™ã€‚\n", + "学振有: yanagi\n", + "学振有: tachibana\n", + "学振無: inoue\n", + "学振無: hayashi\n" + ] + } + ], + "source": [ + "Inoue.abstract()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']\n", + "\n" + ] + } + ], + "source": [ + "l = [1, 2, 3, 4, 5]\n", + "print(dir(l))\n", + "print(type(l))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "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 +} diff --git "a/Inoue/\350\252\262\351\241\214re.ipynb" "b/Inoue/\350\252\262\351\241\214re.ipynb" new file mode 100644 index 0000000..80a0066 --- /dev/null +++ "b/Inoue/\350\252\262\351\241\214re.ipynb" @@ -0,0 +1,251 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#課題1_1~10ã‚’å«ã‚€ãƒªã‚¹ãƒˆä½œæˆ\n", + "l = []\n", + "for i in range(10):\n", + " l.append(i+1)\n", + "l" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 4, 6, 8, 10]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#課題2_1~10ã®å¶æ•°ã®ã¿ã®ãƒªã‚¹ãƒˆä½œæˆ\n", + "l = []\n", + "for i in range(10):\n", + " if (i+1)%2==0:\n", + " l.append(i+1)\n", + "l" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f'}" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#課題3_辞書ã®ä½œæˆ\n", + "l1 = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"]\n", + "l2 = []\n", + "for i in range(6):\n", + " l2.append(i)\n", + "\n", + "d1 = []\n", + "for i, j in zip(l1, l2):\n", + " l3 = [j, i]\n", + " d1.append(l3)\n", + "d2 = dict(d1)\n", + "d2\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#課題4_Humanクラス作æˆ\n", + "class Human:\n", + " counts = 0\n", + " \n", + " def __init__(self, name, age, sex, height, weight):\n", + " self.name = name\n", + " self.age = age\n", + " self.sex = sex\n", + " self.height = height\n", + " self.weight = weight\n", + " Human.counts += 1\n", + "\n", + " def age_increment(self):\n", + " self.age += 1 \n", + " print(self.age)\n", + " \n", + " def instance_counts(self):\n", + " print(Human.counts)" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#課題4_インスタンス作æˆ\n", + "Yamada = Human(\"山田\", 23, \"ç”·\", 170.3, 60.2)\n", + "Takahashi = Human(\"高橋\", 30, \"女\", 165.2, 46.2)" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "24\n" + ] + } + ], + "source": [ + "#課題4_山田ã•ã‚“ã®å¹´é½¢ã‚’インクリメント\n", + "Yamada.age_increment()" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], + "source": [ + "#課題4_作æˆã•れãŸã‚¤ãƒ³ã‚¹ã‚¿ãƒ³ã‚¹ã‚’カウント\n", + "Yamada.instance_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "matrix([[19, 22],\n", + " [43, 50]])" + ] + }, + "execution_count": 130, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#課題5_行列ã®ç©ã‚’計算\n", + "import numpy as np\n", + "\n", + "a = np.matrix([[1,2],[3,4]])\n", + "b = np.matrix([[5,6],[7,8]])\n", + "CrossProduct = np.dot(a,b)\n", + "CrossProduct" + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0.98386991009990743" + ] + }, + "execution_count": 134, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#課題6_ベクトルã®cosを計算\n", + "c = np.array([1,2])\n", + "d = np.array([3,4])\n", + "DotProduct = np.dot(c,d)\n", + "length_c = np.linalg.norm(c)\n", + "length_d = np.linalg.norm(d)\n", + "cos = DotProduct / (length_c * length_d)\n", + "cos" + ] + } + ], + "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 +}