{"id":235,"date":"2014-09-04T05:41:36","date_gmt":"2014-09-03T20:41:36","guid":{"rendered":"https:\/\/www.dogrow.net\/python\/?p=235"},"modified":"2019-10-19T09:00:54","modified_gmt":"2019-10-19T00:00:54","slug":"blog54","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/python\/blog54\/","title":{"rendered":"(54) numpy\u3067\u914d\u5217\u8981\u7d20\u306e\u66f8\u304d\u63db\u3048\u3044\u308d\u3044\u308d"},"content":{"rendered":"<p>10\u884c15\u5217\u306e 0\u884c\u5217\u3092\u4f5c\u308b\u3002<\/p>\n<pre>&gt;&gt;&gt; import numpy as np\r\n&gt;&gt;&gt; m = np.zeros((10,15),dtype=int)\r\n&gt;&gt;&gt; m\r\narray([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])\r\n<\/pre>\n<p>(x,y)=(1,2)\u306e\u8981\u7d20\u306e\u5024\u3092 1\u306b\u5909\u3048\u308b\u3002<\/p>\n<pre>&gt;&gt;&gt; m[1,2]=1\r\n&gt;&gt;&gt; m\r\narray([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])\r\n<\/pre>\n<p>\u884c\u65b9\u5411\u306b 2\u500b\u98db\u3070\u3057\u3001\u5217\u65b9\u5411\u306b 3\u500b\u98db\u3070\u3057\u3067\u8981\u7d20\u306e\u5024\u3092 1\u306b\u5909\u3048\u308b\u3002<\/p>\n<pre>&gt;&gt;&gt; m = np.zeros((10,15),dtype=int)\r\n&gt;&gt;&gt; m[::2,::3]=1\r\n&gt;&gt;&gt; m\r\narray([[1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])\r\n<\/pre>\n<p>\u884c\u65b9\u5411\u306b 1\u884c\u76ee\u304b\u3089 2\u500b\u98db\u3070\u3057\u3001\u5217\u65b9\u5411\u306b2\u304b\u3089 3\u500b\u98db\u3070\u3057\u3067 8\u307e\u3067\u3001\u8981\u7d20\u306e\u5024\u3092 1\u306b\u5909\u3048\u308b\u3002<br \/>\n<span class=\"my_fc_crimsonB\">start:end+1:step \u306e\u3088\u3046\u306bend+1\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u306b\u6ce8\u610f\uff01<\/span><\/p>\n<pre>&gt;&gt;&gt; m = np.zeros((10,15),dtype=int)\r\n&gt;&gt;&gt; m[1::2,2:9:3]=1\r\n&gt;&gt;&gt; m\r\narray([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\r\n       [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0]])\r\n<\/pre>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>10\u884c15\u5217\u306e 0\u884c\u5217\u3092\u4f5c\u308b\u3002 &gt;&gt;&gt; import numpy as np &gt;&gt;&gt; m = np.zeros((10,15),dtype=int) &gt;&gt;&gt; m ar\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/python\/blog54\/\">\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-235","post","type-post","status-publish","format-standard","hentry","category-numpy"],"views":28892,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/235","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=235"}],"version-history":[{"count":10,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":2664,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/235\/revisions\/2664"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/media?parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/categories?post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/tags?post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}