{"id":274,"date":"2014-09-11T21:49:05","date_gmt":"2014-09-11T12:49:05","guid":{"rendered":"https:\/\/www.dogrow.net\/python\/?p=274"},"modified":"2019-10-29T09:35:06","modified_gmt":"2019-10-29T00:35:06","slug":"blog63","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/python\/blog63\/","title":{"rendered":"(63) numpy\u3067\u30bd\u30fc\u30c8\u5f8c\u914d\u5217\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u53d6\u5f97"},"content":{"rendered":"<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u4e71\u6570\u914d\u5217a\u3092\u4f5c\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n&gt;&gt;&gt; import numpy as np\r\n&gt;&gt;&gt; a = np.random.rand(10)\r\n&gt;&gt;&gt; a\r\narray([ 0.4556755 ,  0.82176872,  0.49312231,  0.17689834,  0.96413341,\r\n        0.41666999,  0.91981665,  0.26402886,  0.67935056,  0.80891284])\r\n<\/pre>\n<p>\u914d\u5217\u8981\u7d20\u3092\u30bd\u30fc\u30c8\u3057\u305f\u3044\u5834\u5408\u3001<span class=\"my_fc_deeppinkB\">numpy.sort<\/span> \u3092\u4f7f\u3048\u3070\u3088\u3044\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n&gt;&gt;&gt; b = np.sort(a)\r\n&gt;&gt;&gt; b\r\narray([ 0.17689834,  0.26402886,  0.41666999,  0.4556755 ,  0.49312231,\r\n        0.67935056,  0.80891284,  0.82176872,  0.91981665,  0.96413341])\r\n<\/pre>\n<p>\u964d\u9806\u306b\u3057\u305f\u3044\u5834\u5408\u306f\u30bd\u30fc\u30c8\u5f8c\u306e\u914d\u5217\u3092\u30d5\u30ea\u30c3\u30d7\u3059\u308b\u3002<br \/>\n\u30d5\u30ea\u30c3\u30d7\u306f\u3001\u6700\u7d42\u8981\u7d20[-1]\u304b\u3089-1\u305a\u3064\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u305a\u3089\u3059\u3053\u3068\u306b\u3088\u308a\u5b9f\u73fe\u3059\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n&gt;&gt;&gt; c = <span class=\"my_fc_deeppinkB\">b[-1::-1]<\/span>\r\n&gt;&gt;&gt; c\r\narray([ 0.96413341,\u00a0 0.91981665,\u00a0 0.82176872,\u00a0 0.80891284,\u00a0 0.67935056,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0.49312231,\u00a0 0.4556755 ,\u00a0 0.41666999,\u00a0 0.26402886,\u00a0 0.17689834])\r\n<\/pre>\n<p>\u672c\u984c\u306e <span class=\"my_fc_deeppinkB\">\u30bd\u30fc\u30c8\u5f8c\u306e\u914d\u5217\u8981\u7d20\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u5f97\u308b\u306b\u306f\uff1f<\/span> \u306f <span class=\"my_fc_deeppinkB\">numpy.argsort<\/span> \u3092\u4f7f\u3046\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n&gt;&gt;&gt; x = <span class=\"my_fc_deeppinkB\">np.argsort(a)<\/span>\r\n&gt;&gt;&gt; x\r\narray([3, 7, 5, 0, 2, 8, 9, 1, 6, 4])\r\n<\/pre>\n<p>\u5f97\u3089\u308c\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f7f\u7528\u3057\u3066\u3001\u914d\u5217\u8981\u7d20\u306e\u30bd\u30fc\u30c8\u3082\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n&gt;&gt;&gt; <span class=\"my_fc_deeppinkB\">a[x]<\/span>\r\narray([ 0.17689834,  0.26402886,  0.41666999,  0.4556755 ,  0.49312231,\r\n        0.67935056,  0.80891284,  0.82176872,  0.91981665,  0.96413341])\r\n&gt;&gt;&gt; b - a[x]\r\narray([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])\r\n<\/pre>\n<p>MATLAB\u3082\u305d\u3046\u3060\u3051\u3069\u3001\u3053\u308c\u304c\u3067\u304d\u308b\u306e\u304c\u3068\u3063\u3066\u3082\u4fbf\u5229\u3002<\/p>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u4e71\u6570\u914d\u5217a\u3092\u4f5c\u308b\u3002 &gt;&gt;&gt; import numpy as np &gt;&gt;&gt; a = np.random.rand(10) &gt;&gt;&gt; a array([ 0.4\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/python\/blog63\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-274","post","type-post","status-publish","format-standard","hentry","category-numpy"],"views":25923,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/comments?post=274"}],"version-history":[{"count":13,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/274\/revisions"}],"predecessor-version":[{"id":2779,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/274\/revisions\/2779"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/media?parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/categories?post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/tags?post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}