{"id":21800,"date":"2023-08-04T16:11:25","date_gmt":"2023-08-04T08:11:25","guid":{"rendered":"http:\/\/www.jdcui.com\/?p=21800"},"modified":"2023-08-04T16:15:05","modified_gmt":"2023-08-04T08:15:05","slug":"%e7%bc%96%e7%a8%8b%e7%ac%94%e8%ae%b0-python%e4%b8%adnumpy%e7%9a%84%e6%b1%82%e5%92%8c","status":"publish","type":"post","link":"http:\/\/www.jdcui.com\/?p=21800","title":{"rendered":"[\u7f16\u7a0b][\u7b14\u8bb0] Python\u4e2dnumpy\u7684\u6c42\u548c"},"content":{"rendered":"<p><span style=\"color: #ff00ff; background-color: #ccffcc;\"><strong>\u5b9e\u5e72\u3001\u5b9e\u8df5\u3001\u79ef\u7d2f\u3001\u601d\u8003\u3001\u521b\u65b0\u3002<\/strong><\/span><\/p>\n<hr \/>\n<p>Numpy\u4e2d\u7684Sum\u51fd\u6570\uff0c\u53ef\u4ee5\u5b9e\u73b0\u6309\u884c\u3001\u6309\u5217\u76f8\u52a0\u3002<\/p>\n<p>\u4ee3\u7801\uff1a<\/p>\n<pre>import numpy as np\r\n# A=np.zeros((3,4))\r\nA=np.array([[1,2,3],[4,5,6]])\r\nprint(A)\r\n# \u9010\u4e2a\u5143\u7d20\u6c42\u548c\r\nprint('\u9010\u4e2a\u5143\u7d20\u6c42\u548c')\r\nprint(np.sum(A))\r\n# \u6309\u5217\u53e0\u52a0\r\nprint('\u6309\u5217\u53e0\u52a0')\r\ntemp=np.sum(A,axis = 0)\r\nprint(temp)\r\nprint(temp.shape)\r\n# \u6309\u884c\u53e0\u52a0\r\nprint('\u6309\u884c\u53e0\u52a0')\r\ntemp=np.sum(A,axis = 1)\r\nprint(temp)\r\nprint(temp.shape)\r\n# temp=[temp]\r\n# print(temp)\r\n# print(temp.shape)<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<p><code>[[1 2 3]<\/code><br \/>\n<code>[4 5 6]]<\/code><br \/>\n<code>\u9010\u4e2a\u5143\u7d20\u6c42\u548c<\/code><br \/>\n<code>21<\/code><br \/>\n<code>\u6309\u5217\u53e0\u52a0<\/code><br \/>\n<code>[5 7 9]<\/code><br \/>\n<code>(3,)<\/code><br \/>\n<code>\u6309\u884c\u53e0\u52a0<\/code><br \/>\n<code>[ 6 15]<\/code><br \/>\n<code>(2,)<\/code><\/p>\n<hr \/>\n<p style=\"text-align: center;\"><strong><div  class=\"thumbs-rating-container\" id=\"thumbs-rating-21800\" data-content-id=\"21800\"><button class=\"thumbs-rating-up thumbs-rating-voted\" onclick=\"thumbs_rating_vote(21800, 1);\">Vote Up +6<\/button> <button class=\"thumbs-rating-down\" onclick=\"thumbs_rating_vote(21800, 2);\">Vote Down -0<\/button><span class=\"thumbs-rating-already-voted\">You already voted!<\/span><\/div><\/strong><\/p>\n<ul style=\"list-style-type: square;\">\n<li style=\"text-align: left;\"><span style=\"background-color: #ccffcc;\"><strong>\u5fae\u4fe1\u516c\u4f17\u53f7\u00a0(\u00a0<span style=\"color: #0000ff;\">Wechat\u00a0Subscription<\/span>)<\/strong><\/span><\/li>\n<\/ul>\n<p><a href=\"http:\/\/www.jdcui.com\/wp-content\/uploads\/2017\/01\/QRCODE.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3636\" src=\"http:\/\/www.jdcui.com\/wp-content\/uploads\/2017\/01\/QRCODE.jpg\" alt=\"WeChat_QRCode\" width=\"250\" height=\"255\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>\u6b22\u8fce\u5173\u6ce8\u00a0\u201c<span style=\"color: #ff00ff;\">\u7ed3\u6784\u4e4b\u65c5<\/span>\u201d\u00a0\u5fae\u4fe1\u516c\u4f17\u53f7<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u5e72\u3001\u5b9e\u8df5\u3001\u79ef\u7d2f\u3001\u601d\u8003\u3001\u521b\u65b0\u3002 Numpy\u4e2d\u7684Sum\u51fd\u6570\uff0c\u53ef\u4ee5\u5b9e\u73b0\u6309\u884c\u3001\u6309\u5217\u76f8\u52a0\u3002 \u4ee3\u7801\uff1a import numpy as np # A=np.zeros((3,4)) A=np.array([[1,2,3],[4,5,6]]) print(A) # \u9010\u4e2a\u5143\u7d20\u6c42\u548c print(&#8216;\u9010\u4e2a\u5143\u7d20\u6c42\u548c&#8217;) print(np.sum(A)) # \u6309\u5217\u53e0\u52a0 print(&#8216;\u6309\u5217\u53e0\u52a0&#8217;) temp=np.sum(A,axis = 0) print(temp) print(temp.shape) # \u6309\u884c\u53e0\u52a0 print(&#8216;\u6309\u884c\u53e0\u52a0&#8217;) temp=np.sum(A,axis = 1) print(temp) &#8230;<\/p>\n","protected":false},"author":1,"featured_media":21802,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[997],"tags":[3979,998,876],"class_list":["post-21800","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-numpy","tag-python","tag-sum"],"aioseo_notices":[],"views":1822,"_links":{"self":[{"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/posts\/21800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=21800"}],"version-history":[{"count":0,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/posts\/21800\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/media\/21802"}],"wp:attachment":[{"href":"http:\/\/www.jdcui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=21800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=21800"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=21800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}