{"id":17653,"date":"2022-06-01T03:44:03","date_gmt":"2022-06-01T03:44:03","guid":{"rendered":"https:\/\/club.informatix.co.jp\/?p=17653"},"modified":"2024-10-31T07:14:52","modified_gmt":"2024-10-31T07:14:52","slug":"numpy%e3%81%a7%e3%83%99%e3%82%af%e3%83%88%e3%83%ab-%ef%bd%9cpython%e3%81%a7%e6%95%b0%e5%ad%a6%e3%82%92%e5%ad%a6%e3%81%bc%e3%81%86%ef%bc%81%e3%80%80%e7%ac%ac21%e5%9b%9e","status":"publish","type":"post","link":"https:\/\/club.informatix.co.jp\/?p=17653","title":{"rendered":"NumPy\u3067\u30d9\u30af\u30c8\u30eb <\u5f8c\u7de8>\uff5cPython\u3067\u6570\u5b66\u3092\u5b66\u307c\u3046\uff01 \u7b2c21\u56de"},"content":{"rendered":"<h2><span class=\"ez-toc-section\" id=\"%E3%81%AF%E3%81%98%E3%82%81%E3%81%AB%EF%BD%9C%E3%83%AC%E3%83%9D%E3%83%BC%E3%83%88\"><\/span>\u306f\u3058\u3081\u306b\uff5c\u30ec\u30dd\u30fc\u30c8<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-17479\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/05\/20220503-1.jpg\" alt=\"\" width=\"800\" height=\"391\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/05\/20220503-1.jpg 800w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/05\/20220503-1-300x147.jpg 300w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/05\/20220503-1-768x375.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-17661\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-2.jpg\" alt=\"\" width=\"800\" height=\"391\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-2.jpg 800w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-2-300x147.jpg 300w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-2-768x375.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>\u79c1\u304c\u6bce\u6708\u958b\u50ac\u3057\u3066\u3044\u308b\u685c\u4e95\u9032\u306ePython\uff65UNIX\u6559\u5ba4\u3010\u6570\u5b66\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b3\u30fc\u30b9\u30113\u6708\u3068\u685c\u4e95\u9032\u306e\u6570\u5b66\u6d6a\u6f2b\u7d00\u884c5\u6708\u306e\u30c6\u30fc\u30de\u304c\u300c\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u300d\u3067\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/club.informatix.co.jp\/?p=17472\" target=\"_blank\" rel=\"noopener\">\u524d\u56de<\/a>\u306fPython\u306eNumPy\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u3088\u308b\u30d9\u30af\u30c8\u30eb\u3092\u6271\u3046\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002\u4eca\u56de\u306f\u30d9\u30af\u30c8\u30eb\u306e\u5fdc\u7528\u3068\u3057\u3066\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u76ee\u6b21<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e9523a4da9d\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e9523a4da9d\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/club.informatix.co.jp\/?p=17653\/#%E3%81%AF%E3%81%98%E3%82%81%E3%81%AB%EF%BD%9C%E3%83%AC%E3%83%9D%E3%83%BC%E3%83%88\" >\u306f\u3058\u3081\u306b\uff5c\u30ec\u30dd\u30fc\u30c8<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/club.informatix.co.jp\/?p=17653\/#2%E3%81%A4%E3%81%AE%E3%83%99%E3%82%AF%E3%83%88%E3%83%AB%E3%81%AE%E3%81%AA%E3%81%99%E8%A7%92\" >2\u3064\u306e\u30d9\u30af\u30c8\u30eb\u306e\u306a\u3059\u89d2<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/club.informatix.co.jp\/?p=17653\/#%E3%83%99%E3%82%AF%E3%83%88%E3%83%AB%E3%81%AE%E5%86%85%E7%A9%8D%E3%81%A8%E3%82%B3%E3%82%B5%E3%82%A4%E3%83%B3%E9%A1%9E%E4%BC%BC%E5%BA%A6\" >\u30d9\u30af\u30c8\u30eb\u306e\u5185\u7a4d\u3068\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/club.informatix.co.jp\/?p=17653\/#%E3%82%B3%E3%82%B5%E3%82%A4%E3%83%B3%E9%A1%9E%E4%BC%BC%E5%BA%A6%E3%81%AE%E5%AE%9F%E4%BE%8B\" >\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u306e\u5b9f\u4f8b<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/club.informatix.co.jp\/?p=17653\/#%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%80%8Ccossimpy%E3%80%8D%E3%82%B3%E3%82%B5%E3%82%A4%E3%83%B3%E9%A1%9E%E4%BC%BC%E5%BA%A6%E3%81%AE%E8%A8%88%E7%AE%97%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0\" >\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccossim.py\u300d\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u306e\u8a08\u7b97\u30d7\u30ed\u30b0\u30e9\u30e0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/club.informatix.co.jp\/?p=17653\/#%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C\" >\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u7d50\u679c<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<h2><span class=\"ez-toc-section\" id=\"2%E3%81%A4%E3%81%AE%E3%83%99%E3%82%AF%E3%83%88%E3%83%AB%E3%81%AE%E3%81%AA%E3%81%99%E8%A7%92\"><\/span>2\u3064\u306e\u30d9\u30af\u30c8\u30eb\u306e\u306a\u3059\u89d2<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>2\u3064\u306e\u30d9\u30af\u30c8\u30eb\u306b\u5bfe\u3057\u3066\u3001\u305d\u306e\u89d2\u3092\u8003\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u30022\u3064\u306e\u30d9\u30af\u30c8\u30eb\u306e\u306a\u3059\u89d2\u3092\u03b8\u3068\u3059\u308b\u3068\u3001\u305d\u306e\u53d6\u308a\u5f97\u308b\u7bc4\u56f2\u306f0\u00b0\u2266\u03b8\u2266180\u00b0\u3067\u3059\u3002<\/p>\n<p>\u4f59\u5f26cos\u03b8\u30922\u3064\u306e\u30d9\u30af\u30c8\u30eb\u306e\u6210\u5206\u3092\u7528\u3044\u3066\u6b21\u306e\u56f3\u306e\u3088\u3046\u306b\u6c42\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3088\u3063\u3066\u03b8\u306f\u30a2\u30fc\u30af\u30b3\u30b5\u30a4\u30f3\uff08\u9006\u4f59\u5f26\u95a2\u6570\uff09\u3092\u7528\u3044\u3066\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-17657\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-3.jpg\" alt=\"\" width=\"800\" height=\"683\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-3.jpg 800w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-3-300x256.jpg 300w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-3-768x656.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>\u3053\u306e\u8a08\u7b97\u3092Python\u3067\u3082\u884c\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>&gt;&gt;&gt;\u3000 import numpy as np<br \/>\n&gt;&gt;&gt;\u3000 x = np.array([2, -1, 3, -2])<br \/>\n&gt;&gt;&gt;\u3000 y = np.array([-3, 2, 1, 5])<br \/>\n&gt;&gt;&gt;\u3000 theta = np.dot(x, y)\/(np.linalg.norm(x) * np.linalg.norm(y))<br \/>\n&gt;&gt;&gt;\u3000 print(np.degrees(np.arccos(theta)))<br \/>\n&gt;&gt;&gt;\u3000 124.48138937198158<\/p>\n<p>\u305f\u3057\u304b\u306b\u540c\u3058\u7d50\u679c\u3067\u3059\u3002\u3053\u306e\u8a08\u7b97\u306b\u767b\u5834\u3059\u308bnp.dot(x, y)\u304c\u30d9\u30af\u30c8\u30eb\u306e\u5185\u7a4d\u3067\u3059\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E3%83%99%E3%82%AF%E3%83%88%E3%83%AB%E3%81%AE%E5%86%85%E7%A9%8D%E3%81%A8%E3%82%B3%E3%82%B5%E3%82%A4%E3%83%B3%E9%A1%9E%E4%BC%BC%E5%BA%A6\"><\/span>\u30d9\u30af\u30c8\u30eb\u306e\u5185\u7a4d\u3068\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u30d9\u30af\u30c8\u30ebx\u3068y\u306e\u5185\u7a4d\u3092x\u30fby\u306e\u3088\u3046\u306b\u8868\u3057\u307e\u3059\u3002\u6b21\u306e\u56f3\u306e\u3088\u3046\u306b\u5185\u7a4dx\u30fby\u306f2\u901a\u308a\u3067\u8868\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e1\u306f\u30d9\u30af\u30c8\u30eb\u306e\u30ce\u30eb\u30e0\uff08\u5927\u304d\u3055\uff09\u3068\u306a\u3059\u89d2\u3092\u7528\u3044\u305f\u5f0f\u3001\u305d\u306e2\u306f\u30d9\u30af\u30c8\u30eb\u306e\u6210\u5206\u306b\u3088\u308b\u5f0f\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u30892\u3064\u306e\u5185\u7a4d\u306e\u5f0f\u304a\u3088\u3073\u30d9\u30af\u30c8\u30eb\u306e\u30ce\u30eb\u30e0\u306e\u5f0f\u3088\u308acos\u03b8\u304c\u6210\u5206\u3060\u3051\u3067\u8868\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3053\u306ecos\u03b8\u304c\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u306e\u6b63\u4f53\u3067\u3059\u3002<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-17658\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-4.jpg\" alt=\"\" width=\"800\" height=\"476\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-4.jpg 800w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-4-300x179.jpg 300w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-4-768x457.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>\u30c7\u30fc\u30bf\u3092\u30d9\u30af\u30c8\u30eb\u5316\u3059\u308b\u3053\u3068\u3067\u30012\u3064\u306e\u30c7\u30fc\u30bf\u306e\u6bd4\u8f03\u3092\u30d9\u30af\u30c8\u30eb\u306e\u306a\u3059\u89d2\u306b\u3088\u3063\u3066\u884c\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u03b8\u304c0\u00b0\uff08cos0\u00b0=1\uff09\u306e\u5834\u5408\u3059\u306a\u308f\u30612\u3064\u306e\u30d9\u30af\u30c8\u30eb\u304c\u5e73\u884c\u306e\u5834\u5408\u306f\u30012\u3064\u306e\u30c7\u30fc\u30bf\u306f\u201c\u5b8c\u5168\u306b\u4f3c\u3066\u3044\u308b\u201d\u3068\u3057\u3001\u03b8\u304c180\u00b0\uff08cos180\u00b0=-1\uff09\u306e\u5834\u5408\u3059\u306a\u308f\u30612\u3064\u306e\u30d9\u30af\u30c8\u30eb\u304c\u771f\u53cd\u5bfe\u306e\u5834\u5408\u306f\u30012\u3064\u306e\u30c7\u30fc\u30bf\u306f\u201c\u5168\u304f\u4f3c\u3066\u3044\u306a\u3044\u201d\u3068\u3059\u308b\u89e3\u91c8\u3067\u3059\u3002<\/p>\n<p>\u5b9f\u969b\u306b\u306f\u03b8\u3067\u306f\u306a\u304fcos\u03b8\u3067\u6bd4\u3079\u307e\u3059\u3002<\/p>\n<p>cos0\u00b0\u304c\u6700\u5927\u50241\u3067\u3042\u308b\u5834\u5408\u304c\u3001\u30c7\u30fc\u30bf\u306f\u201c\u5b8c\u5168\u306b\u4f3c\u3066\u3044\u308b\u201d\u3001cos0\u00b0\u304c\u6700\u5c0f\u5024-1\u3067\u3042\u308b\u5834\u5408\u304c\u3001\u30c7\u30fc\u30bf\u306f\u201c\u5168\u304f\u4f3c\u3066\u3044\u306a\u3044\u201d\u3068\u5bfe\u5fdc\u3057\u307e\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u985e\u4f3c\u5ea6\u306fcos\u03b8\u306e\u5927\u5c0f\u306b\u4e00\u81f4\u3057\u307e\u3059\u3002\u3053\u308c\u3092\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\uff08Cosine Similarity\uff09\u3068\u547c\u3073\u3001cos(x,y)\u3068\u8868\u3057\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-17659\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-5.jpg\" alt=\"\" width=\"800\" height=\"500\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-5.jpg 800w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-5-300x188.jpg 300w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-5-768x480.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E3%82%B3%E3%82%B5%E3%82%A4%E3%83%B3%E9%A1%9E%E4%BC%BC%E5%BA%A6%E3%81%AE%E5%AE%9F%E4%BE%8B\"><\/span>\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u306e\u5b9f\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>6\u4eba\u305d\u308c\u305e\u308c\u306b10\u306e\u97f3\u697d\u30b8\u30e3\u30f3\u30eb\u3054\u3068\u306b\u597d\u304d\u5acc\u3044\u306e\u30a2\u30f3\u30b1\u30fc\u30c8\u3092\u3068\u308a\u3001\u305d\u306e\u30c7\u30fc\u30bf\u3092\u3082\u3068\u306b\u97f3\u697d\u306e\u8da3\u5473\u304c\u5408\u30462\u4eba\u3068\u9006\u306b\u8da3\u5473\u304c\u5408\u308f\u306a\u30442\u4eba\u3092\u63a2\u3057\u51fa\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u597d\u304d\u306f\u25cb\u3001\u5acc\u3044\u306f\u25cf\u3001\u3069\u3061\u3089\u3067\u3082\u306a\u3044\u306f\u7a7a\u6b04\u3068\u3057\u307e\u3059\u30026\u4eba\u306e\u7d50\u679c\u3092\u6570\u5024\u5316\u3057\u307e\u3059\u3002<\/p>\n<p>\u25cb\u306f1\u3001\u25cf\u306f-1\u3001\u305d\u3057\u3066\u7a7a\u9593\u306f0\u3068\u3057\u3066\u3001\u307e\u305a\u4e00\u4eba\u4e00\u4eba\u30ea\u30b9\u30c8\u5316\u3057\u307e\u3059\u3002\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u3092\u8a08\u7b97\u3059\u308b\u305f\u3081\u306b\u3001\u3053\u306e\u30ea\u30b9\u30c8\u3092\u30d9\u30af\u30c8\u30eb\u5316\uff081\u6b21\u5143\u914d\u5217\uff09\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001A\uff081\u4f50\u85e4\u3055\u3093\uff09\u306e\u5834\u5408\u306b\u306f\u3001A = [1,1,-1,0,1,-1,0,-1,1,-1]\u3068\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-17660\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-6.jpg\" alt=\"\" width=\"800\" height=\"226\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-6.jpg 800w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-6-300x85.jpg 300w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-6-768x217.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%80%8Ccossimpy%E3%80%8D%E3%82%B3%E3%82%B5%E3%82%A4%E3%83%B3%E9%A1%9E%E4%BC%BC%E5%BA%A6%E3%81%AE%E8%A8%88%E7%AE%97%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0\"><\/span>\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccossim.py\u300d\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u306e\u8a08\u7b97\u30d7\u30ed\u30b0\u30e9\u30e0<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&gt;&gt;&gt;\u3000 import numpy as np<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt;\u3000 # \u597d\u304d\u5acc\u3044\u30c7\u30fc\u30bf<br \/>\n&gt;&gt;&gt;\u3000 A = [1,1,-1,0,1,-1,0,-1,1,-1]<br \/>\n&gt;&gt;&gt;\u3000 B = [-1,1,-1,-1,1,1,1,-1,1,1]<br \/>\n&gt;&gt;&gt;\u3000 C = [1,0,0,0,0,0,-1,1,0,0]<br \/>\n&gt;&gt;&gt;\u3000 D = [0,1,1,1,0,-1,0,1,0,1]<br \/>\n&gt;&gt;&gt;\u3000 E = [-1,-1,-1,-1,-1,-1,1,-1,-1,-1]<br \/>\n&gt;&gt;&gt;\u3000 F = [1,1,1,0,1,1,1,1,-1,1]<br \/>\n&gt;&gt;&gt;\u3000 people = [A, B, C, D, E, F]<br \/>\n&gt;&gt;&gt;\u3000 name = [&#8220;1\u4f50\u85e4\u3055\u3093&#8221;, &#8220;2\u9234\u6728\u3055\u3093&#8221;, &#8220;3\u6b66\u7530\u3055\u3093&#8221;, &#8220;4\u52a0\u85e4\u3055\u3093&#8221;, &#8220;5\u7530\u4e2d\u3055\u3093&#8221;, &#8220;6\u5ca1\u7530\u3055\u3093&#8221;]<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt;\u3000 # \u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u306e\u95a2\u6570\u5b9a\u7fa9<br \/>\n&gt;&gt;&gt;\u3000 def cossim(list1, list2):<br \/>\n&gt;&gt;&gt;\u3000 \u3000vec1 = np.array(list1)<br \/>\n&gt;&gt;&gt;\u3000 \u3000vec2 = np.array(list2)<br \/>\n&gt;&gt;&gt;\u3000\u3000 if (np.linalg.norm(vec1) != 0 and np.linalg.norm(vec2) != 0):<br \/>\n&gt;&gt;&gt;\u3000 \u3000\u3000cos_theta = np.dot(vec1, vec2)\/(np.linalg.norm(vec1)*np.linalg.norm(vec2))<br \/>\n&gt;&gt;&gt;\u3000 \u3000else:<br \/>\n&gt;&gt;&gt;\u3000 \u3000\u3000cos_theta = 0<br \/>\n&gt;&gt;&gt;\u3000 \u3000return cos_theta<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt;\u3000 people_ijcos_list = [] # people[i]\u3068people[j]\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 cos_theta \u306e\u30ea\u30b9\u30c8<br \/>\n&gt;&gt;&gt;\u3000 cos_theta_list = [] # cos_theta \u306e\u30ea\u30b9\u30c8<br \/>\n&gt;&gt;&gt;\u3000 n = len(people) # \u4eba\u6570<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt;\u3000 for i in range(n-1):<br \/>\n&gt;&gt;&gt;\u3000 \u3000for j in range(i+1, n):<br \/>\n&gt;&gt;&gt;\u3000 \u3000\u3000\u3000cos_theta = cossim(people[i], people[j]) # \u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6cos_theta<br \/>\n&gt;&gt;&gt;\u3000 \u3000\u3000\u3000pair_ijcos = name[i]+&#8221;\u3068&#8221;+name[j]+&#8221;\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 &#8220;+str(round(cos_theta, 4))<br \/>\n&gt;&gt;&gt;\u3000 \u3000\u3000\u3000people_ijcos_list.append(pair_ijcos)<br \/>\n&gt;&gt;&gt;\u3000 \u3000\u3000\u3000cos_theta_list.append(cos_theta)<br \/>\n&gt;&gt;&gt;\u3000 \u3000\u3000\u3000print(pair_ijcos)<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt;\u3000 maxpair = cos_theta_list.index(max(cos_theta_list)) # \u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u6700\u5927\u5024\u306e\u30da\u30a2\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9<br \/>\n&gt;&gt;&gt;\u3000 minpair = cos_theta_list.index(min(cos_theta_list)) # \u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u6700\u5c0f\u5024\u306e\u30da\u30a2\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9<br \/>\n&gt;&gt;&gt;\u3000 print(&#8220;\\n\u97f3\u697d\u306e\u8da3\u5473\u304c\u6700\u3082\u985e\u4f3c\u3059\u308b\u4e8c\u4eba\u3000&#8221;, people_ijcos_list[maxpair])<br \/>\n&gt;&gt;&gt;\u3000 print(&#8220;\u97f3\u697d\u306e\u8da3\u5473\u304c\u6700\u3082\u985e\u4f3c\u3057\u306a\u3044\u4e8c\u4eba&#8221;, people_ijcos_list[minpair])<\/p>\n<p>\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u30d5\u30a1\u30a4\u30eb\u306f\u6b21\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/drive.google.com\/file\/d\/1KIs09O3TfoUcmNioFsZ_F19ZbXjKj1CH\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\">https:\/\/drive.google.com\/file\/d\/1KIs09O3TfoUcmNioFsZ_F19ZbXjKj1CH\/view?usp=sharing<\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C\"><\/span>\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u7d50\u679c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&gt;&gt;&gt;\u3000 1\u4f50\u85e4\u3055\u3093\u30682\u9234\u6728\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 0.2236<br \/>\n&gt;&gt;&gt;\u3000 1\u4f50\u85e4\u3055\u3093\u30683\u6b66\u7530\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 0.0<br \/>\n&gt;&gt;&gt;\u3000 1\u4f50\u85e4\u3055\u3093\u30684\u52a0\u85e4\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 -0.1443<br \/>\n&gt;&gt;&gt;\u3000 1\u4f50\u85e4\u3055\u3093\u30685\u7530\u4e2d\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 0.0<br \/>\n&gt;&gt;&gt;\u3000 1\u4f50\u85e4\u3055\u3093\u30686\u5ca1\u7530\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 -0.2357<br \/>\n&gt;&gt;&gt;\u3000 2\u9234\u6728\u3055\u3093\u30683\u6b66\u7530\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 -0.5477<br \/>\n&gt;&gt;&gt;\u3000 2\u9234\u6728\u3055\u3093\u30684\u52a0\u85e4\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 -0.2582<br \/>\n&gt;&gt;&gt;\u3000 2\u9234\u6728\u3055\u3093\u30685\u7530\u4e2d\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 0.0<br \/>\n&gt;&gt;&gt;\u3000 2\u9234\u6728\u3055\u3093\u30686\u5ca1\u7530\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 0.1054<br \/>\n&gt;&gt;&gt;\u3000 3\u6b66\u7530\u3055\u3093\u30684\u52a0\u85e4\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 0.2357<br \/>\n&gt;&gt;&gt;\u3000 3\u6b66\u7530\u3055\u3093\u30685\u7530\u4e2d\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 -0.5477<br \/>\n&gt;&gt;&gt;\u3000 3\u6b66\u7530\u3055\u3093\u30686\u5ca1\u7530\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 0.1925<br \/>\n&gt;&gt;&gt;\u3000 4\u52a0\u85e4\u3055\u3093\u30685\u7530\u4e2d\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 -0.5164<br \/>\n&gt;&gt;&gt;\u3000 4\u52a0\u85e4\u3055\u3093\u30686\u5ca1\u7530\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 0.4082<br \/>\n&gt;&gt;&gt;\u3000 5\u7530\u4e2d\u3055\u3093\u30686\u5ca1\u7530\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 -0.527<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt;\u3000 \u97f3\u697d\u306e\u8da3\u5473\u304c\u6700\u3082\u985e\u4f3c\u3059\u308b\u4e8c\u4eba\u3000 4\u52a0\u85e4\u3055\u3093\u30686\u5ca1\u7530\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 0.4082<br \/>\n&gt;&gt;&gt;\u3000 \u97f3\u697d\u306e\u8da3\u5473\u304c\u6700\u3082\u985e\u4f3c\u3057\u306a\u3044\u4e8c\u4eba 2\u9234\u6728\u3055\u3093\u30683\u6b66\u7530\u3055\u3093\uff1a\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6 -0.5477<\/p>\n<p>6\u4eba\u304b\u30892\u4eba\u9078\u3076\u3059\u3079\u3066\u306e\u7d44\u5408\u305b\u306b\u304a\u3044\u3066\u3001\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u3092\u8a08\u7b97\u3057\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u6700\u5927\u5024\u3068\u6700\u5c0f\u5024\u3092\u691c\u7d22\u3057\u307e\u3059\u3002<\/p>\n<p>\u7d50\u679c\u306f\u30014\u52a0\u85e4\u3055\u3093\u30686\u5ca1\u7530\u3055\u3093\u306e\u76f8\u6027\u304c\u6700\u3082\u826f\u304f\u30012\u9234\u6728\u3055\u3093\u30683\u6b66\u7530\u3055\u3093\u306e\u76f8\u6027\u304c\u6700\u3082\u826f\u304f\u306a\u3044\u3068\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u305e\u308c\u306e\u7d44\u5408\u305b\u3092\u6bd4\u3079\u3066\u307f\u308b\u3068\u3001\u305d\u308c\u306a\u308a\u306b\u7d0d\u5f97\u3067\u304d\u308b\u7d50\u679c\u306e\u3088\u3046\u306b\u3082\u601d\u3048\u307e\u3059\u3002\u5192\u982d\u306e\u300c# \u597d\u304d\u5acc\u3044\u30c7\u30fc\u30bf\u90e8\u5206\u300d\u3092\u3044\u3058\u3063\u3066\u307f\u3066\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u304c\u3069\u306e\u3088\u3046\u306b\u5909\u5316\u3059\u308b\u306e\u304b\u3092\u305f\u3081\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b\uff5c\u30ec\u30dd\u30fc\u30c8 \u79c1\u304c\u6bce\u6708\u958b\u50ac\u3057\u3066\u3044\u308b\u685c\u4e95\u9032\u306ePython\uff65UNIX\u6559\u5ba4\u3010\u6570\u5b66\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b3\u30fc\u30b9\u30113\u6708\u3068\u685c\u4e95\u9032\u306e\u6570\u5b66\u6d6a\u6f2b\u7d00\u884c5\u6708\u306e\u30c6\u30fc\u30de\u304c\u300c\u30b3\u30b5\u30a4\u30f3\u985e\u4f3c\u5ea6\u300d\u3067\u3057\u305f\u3002 \u524d\u56de\u306fPython\u306eNumPy &#8230; <\/p>\n","protected":false},"author":4,"featured_media":17659,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,464,526],"tags":[65,751],"class_list":["post-17653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4","category-hito-star-mathmatics","category-526","tag-python","tag-751"],"jetpack_featured_media_url":"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/06\/20220531-5.jpg","_links":{"self":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/17653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17653"}],"version-history":[{"count":10,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/17653\/revisions"}],"predecessor-version":[{"id":20746,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/17653\/revisions\/20746"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/media\/17659"}],"wp:attachment":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}