{"id":1283,"date":"2017-09-05T23:41:53","date_gmt":"2017-09-05T14:41:53","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=1283"},"modified":"2018-02-25T13:47:02","modified_gmt":"2018-02-25T04:47:02","slug":"numpy%e5%85%a5%e9%96%80-%e5%9f%ba%e6%9c%ac%e7%9a%84%e3%81%aa%e7%b7%9a%e5%bd%a2%e4%bb%a3%e6%95%b0%e8%a8%88%e7%ae%97-%e3%81%9d%e3%81%ae2-%e8%bb%a2%e7%bd%ae%e3%83%bb%e3%83%88%e3%83%ac%e3%83%bc%e3%82%b9","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/1283","title":{"rendered":"NumPy\u5165\u9580  \u57fa\u672c\u7684\u306a\u7dda\u5f62\u4ee3\u6570\u8a08\u7b97 \u305d\u306e2 \u8ee2\u7f6e\u30fb\u30c8\u30ec\u30fc\u30b9\u30fb\u9006\u884c\u5217\u30fb\u884c\u5217\u5f0f"},"content":{"rendered":"<p>\u4eca\u56de\u306f\u9006\u884c\u5217\u3001\u8ee2\u7f6e\u3001\u30c8\u30ec\u30fc\u30b9\u3001\u884c\u5217\u5f0f\u306e\u53d6\u5f97\u65b9\u6cd5\u306b\u3064\u3044\u3066\u5b66\u7fd2\u3057\u307e\u3059\u3002<\/p>\n<p>\u8ee2\u7f6e\u3001\u30c8\u30ec\u30fc\u30b9\u306fndarray\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30e1\u30bd\u30c3\u30c9\u3084\u30d7\u30ed\u30d1\u30c6\u30a3\u3067\u7b97\u51fa\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u9006\u884c\u5217\u3001\u884c\u5217\u5f0f\u306f<a href=\"http:\/\/www.python.ambitious-engineer.com\/archives\/1279\">\u524d\u56de<\/a>\u4f7f\u7528\u3057\u305flinalg\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<h2>\u8ee2\u7f6e<\/h2>\n<p>\u30d7\u30ed\u30d1\u30c6\u30a3T\u3067\u884c\u5217\u306e\u8ee2\u7f6e\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3044\u304f\u3064\u304b\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\n\r\na = np.array([1, 2, 3])\r\na.T\r\n# array([1, 2, 3])\r\n\r\nb = np.array([[1], [2], [3]])\r\n# array([[1],\r\n#        [2],\r\n#        [3]])\r\n\r\nb.T\r\n# array([[1, 2, 3]])\r\n\r\nc = np.array([[1, 2], [3, 4]])\r\n# array([[1, 2],\r\n#        [3, 4]])\r\n\r\nc.T\r\n# array([[1, 3],\r\n#        [2, 4]])\r\n# \r\n\r\n<\/pre>\n<h2>\u30c8\u30ec\u30fc\u30b9<\/h2>\n<p>\u884c\u5217\u306e\u5bfe\u89d2\u6210\u5206\u306e\u548c\u3092\u30c8\u30ec\u30fc\u30b9\u3068\u547c\u3073\u307e\u3059\u3002\u30c8\u30ec\u30fc\u30b9\u306e\u7b97\u51fa\u306ftrace\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\n\r\na = np.array([[1, 2], [3, 4]])\r\n# array([[1, 2],\r\n#        [3, 4]])\r\n\r\na.trace()\r\n# 5\r\n# \r\n<\/pre>\n<p>(\u86c7\u8db3\u306a\u6c17\u3082\u3057\u307e\u3059\u304c)\u3001\u4e00\u822c\u7684\u306b\u306f\u6b63\u65b9\u884c\u5217\u306e\u307f\u306b\u5b9a\u7fa9\u3055\u308c\u308b\u30c8\u30ec\u30fc\u30b9\u3001numpy\u3067\u306f1,1\u6210\u5206\u304b\u3089\u659c\u3081\u306b\u884c\u3051\u308b\u3068\u3053\u308d\u307e\u3067\u8a08\u7b97\u3057\u307e\u3059\u3002\u4f8b\u5916\u3092\u671f\u5f85\u3057\u305f\u5b9f\u88c5\u3092\u3059\u308b\u3068\u554f\u984c\u3092\u898b\u904e\u3054\u3057\u3066\u3057\u307e\u3046\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\n\r\nb = np.array([[1, 2, 3], [4, 5, 6]])\r\n# array([[1, 2, 3],\r\n#        [4, 5, 6]])\r\n\r\nb.trace()\r\n# 6\r\n\r\n\r\nc = np.array([[1, 2], [3, 4], [5, 6]])\r\n# array([[1, 2],\r\n#        [3, 4],\r\n#        [5, 6]])\r\n# \r\n\r\nc.trace()\r\n# 5\r\n# \r\n<\/pre>\n<h2>\u9006\u884c\u5217<\/h2>\n<p>linalg.inv\u30e1\u30bd\u30c3\u30c9\u3067\u9006\u884c\u5217\u3092\u6c42\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\n\r\na = np.array([[1, 2], [3, 4]])\r\n# array([[1, 2],\r\n#        [3, 4]])\r\n\r\na_inv = np.linalg.inv(a)\r\n# array([[-2. ,  1. ],\r\n#        [ 1.5, -0.5]])\r\n\r\n# \u691c\u7b97\u3057\u3066\u307f\u308b\r\nnp.dot(a, a_inv)\r\n# array([[  1.00000000e+00,   1.11022302e-16],\r\n#        [  0.00000000e+00,   1.00000000e+00]])\r\n# \r\n\r\n<\/pre>\n<p>\u6700\u5f8c\u306e\u8a08\u7b97\u3067\u884c\u5217\u306e\u7a4d\u3067\u5358\u4f4d\u884c\u5217\u306b\u306a\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u304c\u8aa4\u5dee\u304c\u767a\u751f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u884c\u5217\u5f0f<\/h2>\n<p>\u884c\u5217\u5f0f\u306flinalg.det\u3067\u6c42\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\na = np.array([[1, 2], [3, 4]])\r\n# array([[1, 2],\r\n#        [3, 4]])\r\n\r\n\r\ndet_a = np.linalg.det(a)\r\n# -2.0000000000000004\r\n<\/pre>\n<p>1 * 4 - 2 *3 = -2\u306a\u306e\u3067\u307b\u307c\u6b63\u3057\u3044\u5024\u304c\u53d6\u5f97\u3067\u304d\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306f\u9006\u884c\u5217\u3001\u8ee2\u7f6e\u3001\u30c8\u30ec\u30fc\u30b9\u3001\u884c\u5217\u5f0f\u306e\u53d6\u5f97\u65b9\u6cd5\u306b\u3064\u3044\u3066\u5b66\u7fd2\u3057\u307e\u3059\u3002 \u8ee2\u7f6e\u3001\u30c8\u30ec\u30fc\u30b9\u306fndarray\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30e1\u30bd\u30c3\u30c9\u3084\u30d7\u30ed\u30d1\u30c6\u30a3\u3067\u7b97\u51fa\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \u9006\u884c\u5217\u3001\u884c\u5217\u5f0f\u306f\u524d\u56de\u4f7f\u7528\u3057\u305flinalg\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002 \u8ee2\u7f6e...<\/p>\n","protected":false},"author":1,"featured_media":1607,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[168],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1283"}],"collection":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/comments?post=1283"}],"version-history":[{"count":3,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1283\/revisions"}],"predecessor-version":[{"id":3516,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1283\/revisions\/3516"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/1607"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=1283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=1283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=1283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}