{"id":117,"date":"2014-07-10T21:50:53","date_gmt":"2014-07-10T12:50:53","guid":{"rendered":"https:\/\/www.dogrow.net\/python\/?p=117"},"modified":"2019-10-29T09:20:44","modified_gmt":"2019-10-29T00:20:44","slug":"blog32","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/python\/blog32\/","title":{"rendered":"(32) max\u3068argmax"},"content":{"rendered":"<h1 class=\"my_h\">\u4ed5\u69d8<\/h1>\n<p><span class=\"my_fc_deeppinkB\">max ( n )<\/span> \u306f\u3001\u914d\u5217\u306e <span class=\"my_fc_deeppinkB\">n<\/span> \u6b21\u5143\u76ee\u306e\u6700\u5927\u5024\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002<br \/>\n<span class=\"my_fc_deeppinkB\">argmax ( n )<\/span> \u306f\u3001\u914d\u5217\u306e <span class=\"my_fc_deeppinkB\">n<\/span> \u6b21\u5143\u76ee\u306e\u6700\u5927\u5024\u3092\u6301\u3064\u8981\u7d20\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<h1 class=\"my_h\">\u4f7f\u7528\u4f8b<\/h1>\n<p>\u914d\u5217 a \u3092\u4e71\u6570\u3067\u4f5c\u6210\u3059\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.floor(np.random.rand(4,3)*10)\r\n&gt;&gt;&gt; a\r\narray([[ 3.,  3.,  0.],\r\n       [ 0.,  5.,  4.],\r\n       [ 8.,  0.,  1.],\r\n       [ 1.,  5.,  6.]])\r\n<\/pre>\n<h3 class=\"my_h\">[0] \u5217\u65b9\u5411<\/h3>\n<p>\u5217\u65b9\u5411\uff08\u2193\uff09\u306e\u6700\u5927\u5024\u304a\u3088\u3073\u3001\u6700\u5927\u5024\u3092\u6301\u3064\u8981\u7d20\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u53d6\u5f97\u3057\u3066\u307f\u308b\u3002<br \/>\n\u76ee\u8996\u3067\u8abf\u3079\u308b\u3068\u671f\u5f85\u3059\u308b\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3060\u304c&#8230;<br \/>\n<span class=\"my_fc_darkgray\">0\u5217\u76ee<\/span> a[ * ][ 0 ] \u3067\u306f\u3001a[ <span class=\"my_fc_blue my_fw_bold\">2<\/span> ][ 0 ] \u306e <span class=\"my_fc_red my_fw_bold\">8<\/span><br \/>\n<span class=\"my_fc_darkgray\">1\u5217\u76ee<\/span> a[ * ][ 1 ] \u3067\u306f\u3001a[ <span class=\"my_fc_blue my_fw_bold\">1 <\/span>][ 1 ], a[ <span class=\"my_fc_blue my_fw_bold\">3 <\/span>][ 1 ] \u306e <span class=\"my_fc_red my_fw_bold\">5<\/span><br \/>\n<span class=\"my_fc_darkgray\">2\u5217\u76ee<\/span> a[ * ][ 2 ] \u3067\u306f\u3001a[ <span class=\"my_fc_blue my_fw_bold\">3 <\/span>][ 2 ] \u306e <span class=\"my_fc_red my_fw_bold\">6<\/span><\/p>\n<pre class=\"my_pre_python\">\r\n&gt;&gt;&gt; a.max(<span class=\"my_fc_deeppink my_fw_bold\">0<\/span>)\r\narray([ <span class=\"my_fc_red my_fw_bold\">8<\/span>.,  <span class=\"my_fc_red my_fw_bold\">5<\/span>.,  <span class=\"my_fc_red my_fw_bold\">6<\/span>.])\r\n&gt;&gt;&gt; a.argmax(<span class=\"my_fc_deeppink my_fw_bold\">0<\/span>)\r\narray([<span class=\"my_fc_blue my_fw_bold\">2<\/span>, <span class=\"my_fc_blue my_fw_bold\">1<\/span>, <span class=\"my_fc_blue my_fw_bold\">3<\/span>])\r\n<\/pre>\n<p><span class=\"my_fc_blue my_fw_bold\">OK <\/span>\u3060\u3002<br \/>\n\u305f\u3060\u3057\u3001\u540c\u3058\u5024\u306e\u8981\u7d20\u304c\u8907\u6570\u500b\u5b58\u5728\u3059\u308b\u5834\u5408\u306f\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u5024\u306e\u5c0f\u3055\u306a\u65b9\u306e\u307f\u6559\u3048\u3066\u304f\u308c\u308b\u3002<\/p>\n<h3 class=\"my_h\">[1] \u884c\u65b9\u5411<\/h3>\n<p>\u6b21\u306b\u884c\u65b9\u5411\uff08\u2192\uff09\u306e\u6700\u5927\u5024\u304a\u3088\u3073\u3001\u6700\u5927\u5024\u3092\u6301\u3064\u8981\u7d20\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u53d6\u5f97\u3057\u3066\u307f\u308b\u3002<br \/>\n\u76ee\u8996\u3067\u8abf\u3079\u308b\u3068\u671f\u5f85\u3059\u308b\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3060\u304c&#8230;<br \/>\n<span class=\"my_fc_darkgray\">0\u884c\u76ee<\/span> a[ 0 ][ * ] \u3067\u306f\u3001a[ 0 ][ <span class=\"my_fc_blue my_fw_bold\">0<\/span> ], a[ 0 ][ <span class=\"my_fc_blue my_fw_bold\">1<\/span> ] \u306e <span class=\"my_fc_red my_fw_bold\">3<\/span><br \/>\n<span class=\"my_fc_darkgray\">1\u884c\u76ee<\/span> a[ 1 ][ * ] \u3067\u306f\u3001a[ 1 ][ <span class=\"my_fc_blue my_fw_bold\">1<\/span> ] \u306e <span class=\"my_fc_red my_fw_bold\">5<\/span><br \/>\n<span class=\"my_fc_darkgray\">2\u884c\u76ee<\/span> a[ 2 ][ * ] \u3067\u306f\u3001a[ 2 ][ <span class=\"my_fc_blue my_fw_bold\">0<\/span> ] \u306e <span class=\"my_fc_red my_fw_bold\">8<\/span><br \/>\n<span class=\"my_fc_darkgray\">3\u884c\u76ee<\/span> a[ 3 ][ * ] \u3067\u306f\u3001a[ 3 ][ <span class=\"my_fc_blue my_fw_bold\">2<\/span> ] \u306e <span class=\"my_fc_red my_fw_bold\">6<\/span><\/p>\n<pre class=\"my_pre_python\">\r\n&gt;&gt;&gt; a.max(<span class=\"my_fc_deeppink my_fw_bold\">1<\/span>)\r\narray([ <span class=\"my_fc_red my_fw_bold\">3<\/span>.,  <span class=\"my_fc_red my_fw_bold\">5<\/span>.,  <span class=\"my_fc_red my_fw_bold\">8<\/span>.,  <span class=\"my_fc_red my_fw_bold\">6<\/span>.])\r\n&gt;&gt;&gt; a.argmax(<span class=\"my_fc_deeppink my_fw_bold\">1<\/span>)\r\narray([<span class=\"my_fc_blue my_fw_bold\">0<\/span>, <span class=\"my_fc_blue my_fw_bold\">1<\/span>, <span class=\"my_fc_blue my_fw_bold\">0<\/span>, <span class=\"my_fc_blue my_fw_bold\">2<\/span>])\r\n<\/pre>\n<p><span class=\"my_fc_blue my_fw_bold\">OK <\/span>\u3060\u3002<br \/>\n\u3053\u3061\u3089\u3082\u540c\u3058\u5024\u306e\u8981\u7d20\u304c\u8907\u6570\u500b\u5b58\u5728\u3059\u308b\u5834\u5408\u306f\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u5024\u306e\u5c0f\u3055\u306a\u65b9\u306e\u307f\u6559\u3048\u3066\u304f\u308c\u308b\u3002<\/p>\n<h3 class=\"my_h\">\u305d\u306e\u4ed6<\/h3>\n<p>\u5f53\u7136\u3060\u304c 3\u6b21\u5143\u4ee5\u4e0a\u3067\u3082\u540c\u3058\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<p>\u307e\u305f\u3001max, argmax \u306e\u5f15\u6570\u3067\u8ef8\u756a\u53f7\u3092\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u3001\u5168\u8981\u7d20\u3092\u5bfe\u8c61\u306b\u6700\u5927\u5024\u3092\u63a2\u3057\u3066\u304f\u308c\u308b\u3002<br \/>\n\u3053\u306e\u5834\u5408\u3001a.argmax()\u306f\u3001\u914d\u5217\u3092 1\u6b21\u5143\u306b\u76f4\u5217\u306b\u5c55\u958b\u3057\u305f\u3068\u304d\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u5024\u3092\u8fd4\u3059\u4ed5\u69d8\u3060\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n>>> a.max()\r\n8.0\r\n>>>\r\n>>> a.argmax()\r\n6\r\n<\/pre>\n<p>\u78ba\u304b\u306b\u6700\u5927\u5024 8\u306f a\u3092\u76f4\u5217\u5c55\u958b\u5f8c\u306b index=6\u306e\u4f4d\u7f6e\u306b\u3042\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n>>> a\r\narray([[ 3.,  3.,  0.],\r\n       [ 0.,  5.,  4.],\r\n       [ 8.,  0.,  1.],\r\n       [ 1.,  5.,  6.]])\r\n>>> a.reshape(-1)\r\narray([ 3.,  3.,  0.,  0.,  5.,  4.,  8.,  0.,  1.,  1.,  5.,  6.])\r\n<\/pre>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>\u4ed5\u69d8 max ( n ) \u306f\u3001\u914d\u5217\u306e n \u6b21\u5143\u76ee\u306e\u6700\u5927\u5024\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002 argmax ( n ) \u306f\u3001\u914d\u5217\u306e n \u6b21\u5143\u76ee\u306e\u6700\u5927\u5024\u3092\u6301\u3064\u8981\u7d20\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002 \u4f7f\u7528\u4f8b \u914d\u5217 a \u3092\u4e71\u6570\u3067\u4f5c\u6210\u3059\u308b\u3002 &gt;&#038;gt\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/python\/blog32\/\">\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-117","post","type-post","status-publish","format-standard","hentry","category-numpy"],"views":20466,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/117","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=117"}],"version-history":[{"count":52,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":2769,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/117\/revisions\/2769"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}