{"id":1003527,"date":"2024-12-27T10:18:00","date_gmt":"2024-12-27T02:18:00","guid":{"rendered":""},"modified":"2024-12-27T10:18:02","modified_gmt":"2024-12-27T02:18:02","slug":"python%e6%95%b0%e7%bb%84%e7%9b%b8%e5%8a%a0%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1003527.html","title":{"rendered":"python\u6570\u7ec4\u76f8\u52a0\u5982\u4f55\u5b9e\u73b0"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25080832\/9cb9b564-cf16-4ee8-b921-810dbd8941bc.webp\" alt=\"python\u6570\u7ec4\u76f8\u52a0\u5982\u4f55\u5b9e\u73b0\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u7684add\u51fd\u6570\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001zip\u51fd\u6570\u3001\u5faa\u73af\u8fed\u4ee3\u7b49\u65b9\u6cd5\u3002NumPy\u5e93\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\uff0c\u5c24\u5176\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\uff0c\u800c\u5217\u8868\u63a8\u5bfc\u5f0f\u548czip\u51fd\u6570\u5219\u9002\u7528\u4e8e\u8f83\u5c0f\u89c4\u6a21\u7684\u6570\u636e\u5904\u7406\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528NumPy\u5e93\u662f\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0\u7684\u6700\u5e38\u7528\u548c\u9ad8\u6548\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002NumPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u591a\u79cd\u6570\u7ec4\u64cd\u4f5c\u51fd\u6570\uff0c<code>numpy.add<\/code>\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u5bf9\u4e24\u4e2a\u6570\u7ec4\u8fdb\u884c\u9010\u5143\u7d20\u76f8\u52a0\u64cd\u4f5c\u3002\u4e3a\u4e86\u4f7f\u7528NumPy\uff0c\u4f60\u9700\u8981\u5148\u5b89\u88c5NumPy\u5e93\uff0c\u7136\u540e\u5bfc\u5165\u5b83\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528NumPy\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684Python\u73af\u5883\u4e2d\u5b89\u88c5\u4e86NumPy\u5e93\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5NumPy\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u8fdb\u884c\u6570\u7ec4\u76f8\u52a0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e24\u4e2a\u6570\u7ec4<\/strong><\/h2>\n<p>array1 = np.array([1, 2, 3])<\/p>\n<p>array2 = np.array([4, 5, 6])<\/p>\n<h2><strong>\u4f7f\u7528numpy.add\u51fd\u6570\u8fdb\u884c\u9010\u5143\u7d20\u76f8\u52a0<\/strong><\/h2>\n<p>result = np.add(array1, array2)<\/p>\n<p>print(&quot;\u7ed3\u679c\u6570\u7ec4:&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0NumPy\u5e93\u7684\u4f18\u52bf\uff1a<\/strong><\/p>\n<\/p>\n<p><p>NumPy\u5e93\u7684\u4e3b\u8981\u4f18\u52bf\u5728\u4e8e\u5176\u9ad8\u6548\u6027\u548c\u7b80\u6d01\u6027\u3002NumPy\u5e95\u5c42\u4f7f\u7528C\u8bed\u8a00\u5b9e\u73b0\uff0c\u4f7f\u5f97\u5176\u6570\u7ec4\u64cd\u4f5c\u901f\u5ea6\u975e\u5e38\u5feb\u3002\u76f8\u6bd4\u4e8ePython\u7684\u5185\u7f6e\u5217\u8868\uff0cNumPy\u6570\u7ec4\uff08ndarray\uff09\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\u5177\u6709\u663e\u8457\u7684\u6027\u80fd\u4f18\u52bf\u3002\u6b64\u5916\uff0cNumPy\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u5b66\u51fd\u6570\uff0c\u80fd\u591f\u65b9\u4fbf\u5730\u5bf9\u6570\u7ec4\u8fdb\u884c\u5404\u79cd\u6570\u5b66\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<hr>\n<p><p><strong>\u4e00\u3001NUMPY\u5e93\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0<\/strong><\/p>\n<\/p>\n<p><p>NumPy\u5e93\u662fPython\u4e2d\u975e\u5e38\u6d41\u884c\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\u548c\u4e30\u5bcc\u7684\u6570\u5b66\u51fd\u6570\u3002\u4f7f\u7528NumPy\u5e93\u8fdb\u884c\u6570\u7ec4\u76f8\u52a0\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u4f7f\u7528<code>numpy.add<\/code>\u51fd\u6570\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e24\u4e2aNumPy\u6570\u7ec4<\/strong><\/h2>\n<p>array1 = np.array([10, 20, 30])<\/p>\n<p>array2 = np.array([1, 2, 3])<\/p>\n<h2><strong>\u4f7f\u7528numpy.add\u51fd\u6570\u8fdb\u884c\u9010\u5143\u7d20\u76f8\u52a0<\/strong><\/h2>\n<p>result = np.add(array1, array2)<\/p>\n<p>print(&quot;\u7ed3\u679c\u6570\u7ec4:&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c<code>numpy.add<\/code>\u51fd\u6570\u5bf9\u4e24\u4e2a\u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u76f8\u52a0\u64cd\u4f5c\uff0c\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u6570\u7ec4\u3002NumPy\u7684\u4f18\u52bf\u5728\u4e8e\u5176\u9ad8\u6548\u6027\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0cNumPy\u80fd\u591f\u663e\u8457\u63d0\u5347\u8fd0\u7b97\u901f\u5ea6\u3002<\/p>\n<\/p>\n<p><p><strong>NumPy\u6570\u7ec4\u64cd\u4f5c\u7684\u6027\u80fd\u4f18\u52bf<\/strong><\/p>\n<\/p>\n<p><p>NumPy\u6570\u7ec4\u7684\u6027\u80fd\u4f18\u52bf\u4e3b\u8981\u6e90\u4e8e\u5176\u5e95\u5c42\u5b9e\u73b0\u3002NumPy\u4f7f\u7528C\u8bed\u8a00\u7f16\u5199\uff0c\u80fd\u591f\u76f4\u63a5\u64cd\u4f5c\u5185\u5b58\uff0c\u4ece\u800c\u907f\u514d\u4e86Python\u89e3\u91ca\u5668\u7684\u5f00\u9500\u3002\u6b64\u5916\uff0cNumPy\u7684\u6570\u7ec4\u64cd\u4f5c\u662f\u5411\u91cf\u5316\u7684\uff0c\u8fd9\u610f\u5473\u7740\u53ef\u4ee5\u5728\u4e0d\u4f7f\u7528\u663e\u5f0f\u5faa\u73af\u7684\u60c5\u51b5\u4e0b\u5bf9\u6574\u4e2a\u6570\u7ec4\u8fdb\u884c\u64cd\u4f5c\uff0c\u4ece\u800c\u8fdb\u4e00\u6b65\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<\/p>\n<hr>\n<p><p><strong>\u4e8c\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u8fdb\u884c\u6570\u7ec4\u76f8\u52a0<\/strong><\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u8f83\u5c0f\u89c4\u6a21\u7684\u6570\u636e\u5904\u7406\uff0cPython\u7684\u5217\u8868\u63a8\u5bfc\u5f0f\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u6d01\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0\u3002\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u751f\u6210\u5217\u8868\u7684\u7b80\u6d01\u8bed\u6cd5\uff0c\u80fd\u591f\u5728\u4e00\u884c\u4ee3\u7801\u4e2d\u5b9e\u73b0\u590d\u6742\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e24\u4e2a\u5217\u8868<\/p>\n<p>list1 = [5, 10, 15]<\/p>\n<p>list2 = [2, 4, 6]<\/p>\n<h2><strong>\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u5b9e\u73b0\u9010\u5143\u7d20\u76f8\u52a0<\/strong><\/h2>\n<p>result = [x + y for x, y in zip(list1, list2)]<\/p>\n<p>print(&quot;\u7ed3\u679c\u5217\u8868:&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c<code>zip<\/code>\u51fd\u6570\u5c06\u4e24\u4e2a\u5217\u8868\u4e2d\u7684\u5143\u7d20\u914d\u5bf9\uff0c\u5217\u8868\u63a8\u5bfc\u5f0f\u5219\u901a\u8fc7\u9010\u5bf9\u5143\u7d20\u76f8\u52a0\u751f\u6210\u65b0\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<p><p><strong>\u5217\u8868\u63a8\u5bfc\u5f0f\u7684\u7b80\u6d01\u6027<\/strong><\/p>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u7684\u4f18\u52bf\u5728\u4e8e\u5176\u7b80\u6d01\u6027\uff0c\u80fd\u591f\u5728\u4e00\u884c\u4ee3\u7801\u4e2d\u5b8c\u6210\u6570\u7ec4\u76f8\u52a0\u64cd\u4f5c\u3002\u7136\u800c\uff0c\u7531\u4e8ePython\u5217\u8868\u4e0d\u5177\u5907NumPy\u6570\u7ec4\u7684\u9ad8\u6548\u6027\uff0c\u56e0\u6b64\u5bf9\u4e8e\u5927\u89c4\u6a21\u6570\u636e\u5904\u7406\uff0c\u4ecd\u63a8\u8350\u4f7f\u7528NumPy\u5e93\u3002<\/p>\n<\/p>\n<hr>\n<p><p><strong>\u4e09\u3001\u4f7f\u7528zip\u51fd\u6570\u548c\u5faa\u73af\u8fed\u4ee3\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0<\/strong><\/p>\n<\/p>\n<p><p>\u9664\u4e86\u5217\u8868\u63a8\u5bfc\u5f0f\uff0cPython\u7684<code>zip<\/code>\u51fd\u6570\u4e0e\u5faa\u73af\u8fed\u4ee3\u7ed3\u5408\u4f7f\u7528\uff0c\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0\u3002\u8fd9\u79cd\u65b9\u6cd5\u66f4\u52a0\u76f4\u89c2\uff0c\u9002\u5408\u521d\u5b66\u8005\u7406\u89e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e24\u4e2a\u5217\u8868<\/p>\n<p>list1 = [7, 8, 9]<\/p>\n<p>list2 = [1, 2, 3]<\/p>\n<h2><strong>\u4f7f\u7528zip\u51fd\u6570\u548c\u5faa\u73af\u8fed\u4ee3\u5b9e\u73b0\u9010\u5143\u7d20\u76f8\u52a0<\/strong><\/h2>\n<p>result = []<\/p>\n<p>for x, y in zip(list1, list2):<\/p>\n<p>    result.append(x + y)<\/p>\n<p>print(&quot;\u7ed3\u679c\u5217\u8868:&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>zip\u51fd\u6570\u4e0e\u5faa\u73af\u8fed\u4ee3\u7684\u7ed3\u5408<\/strong><\/p>\n<\/p>\n<p><p><code>zip<\/code>\u51fd\u6570\u80fd\u591f\u5c06\u591a\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff08\u5982\u5217\u8868\u3001\u5143\u7ec4\uff09\u4e2d\u7684\u5143\u7d20\u914d\u5bf9\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\u3002\u901a\u8fc7\u5faa\u73af\u8fed\u4ee3\uff0c\u53ef\u4ee5\u5bf9\u8fd9\u4e9b\u914d\u5bf9\u5143\u7d20\u8fdb\u884c\u9010\u4e00\u64cd\u4f5c\u3002\u867d\u7136\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u5982\u5217\u8868\u63a8\u5bfc\u5f0f\u7b80\u6d01\uff0c\u4f46\u66f4\u52a0\u76f4\u89c2\uff0c\u9002\u5408\u4e8e\u590d\u6742\u7684\u6570\u7ec4\u64cd\u4f5c\u573a\u666f\u3002<\/p>\n<\/p>\n<hr>\n<p><p><strong>\u56db\u3001\u4f7f\u7528\u5faa\u73af\u904d\u5386\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u4e0d\u4f7f\u7528\u4efb\u4f55\u989d\u5916\u5e93\u7684\u60c5\u51b5\u4e0b\uff0cPython\u7684\u5faa\u73af\u904d\u5386\u4e5f\u662f\u4e00\u79cd\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0\u7684\u57fa\u672c\u65b9\u6cd5\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u4efb\u4f55\u53ef\u8fed\u4ee3\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e24\u4e2a\u5217\u8868<\/p>\n<p>list1 = [3, 6, 9]<\/p>\n<p>list2 = [1, 4, 7]<\/p>\n<h2><strong>\u4f7f\u7528\u5faa\u73af\u904d\u5386\u5b9e\u73b0\u9010\u5143\u7d20\u76f8\u52a0<\/strong><\/h2>\n<p>result = []<\/p>\n<p>for i in range(len(list1)):<\/p>\n<p>    result.append(list1[i] + list2[i])<\/p>\n<p>print(&quot;\u7ed3\u679c\u5217\u8868:&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u5faa\u73af\u904d\u5386\u7684\u7075\u6d3b\u6027<\/strong><\/p>\n<\/p>\n<p><p>\u5faa\u73af\u904d\u5386\u65b9\u6cd5\u7684\u7075\u6d3b\u6027\u5728\u4e8e\u53ef\u4ee5\u5bf9\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u590d\u6742\u64cd\u4f5c\uff0c\u4e0d\u4ec5\u9650\u4e8e\u76f8\u52a0\u3002\u540c\u65f6\uff0c\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u4f9d\u8d56\u4e8e\u4efb\u4f55\u7b2c\u4e09\u65b9\u5e93\uff0c\u9002\u5408\u4e8e\u5bf9Python\u57fa\u7840\u8bed\u6cd5\u7684\u5b66\u4e60\u548c\u7406\u89e3\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u5927\u89c4\u6a21\u6570\u636e\u5904\u7406\uff0c\u8fd9\u79cd\u65b9\u6cd5\u7684\u6548\u7387\u8f83\u4f4e\u3002<\/p>\n<\/p>\n<hr>\n<p><p><strong>\u4e94\u3001NumPy\u5e93\u7684\u6269\u5c55\u529f\u80fd<\/strong><\/p>\n<\/p>\n<p><p>\u9664\u4e86\u57fa\u672c\u7684\u6570\u7ec4\u76f8\u52a0\u529f\u80fd\uff0cNumPy\u5e93\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u5176\u4ed6\u9ad8\u7ea7\u529f\u80fd\uff0c\u5982\u6570\u7ec4\u7684\u5e7f\u64ad\u3001\u77e9\u9635\u8fd0\u7b97\u3001\u591a\u7ef4\u6570\u7ec4\u64cd\u4f5c\u7b49\u3002\u638c\u63e1\u8fd9\u4e9b\u529f\u80fd\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u6570\u636e\u5904\u7406\u548c\u79d1\u5b66\u8ba1\u7b97\u4e2d\u66f4\u52a0\u9ad8\u6548\u5730\u5b8c\u6210\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><p><strong>NumPy\u6570\u7ec4\u7684\u5e7f\u64ad\u673a\u5236<\/strong><\/p>\n<\/p>\n<p><p>NumPy\u7684\u5e7f\u64ad\u673a\u5236\u5141\u8bb8\u4e0d\u540c\u5f62\u72b6\u7684\u6570\u7ec4\u8fdb\u884c\u8fd0\u7b97\u3002\u5f53\u4e24\u4e2a\u6570\u7ec4\u7684\u7ef4\u5ea6\u4e0d\u540c\u65f6\uff0cNumPy\u4f1a\u81ea\u52a8\u6269\u5c55\u8f83\u5c0f\u7684\u6570\u7ec4\u4ee5\u5339\u914d\u8f83\u5927\u7684\u6570\u7ec4\uff0c\u4ece\u800c\u5b9e\u73b0\u9010\u5143\u7d20\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\u548c\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4<\/strong><\/h2>\n<p>array1 = np.array([1, 2, 3])<\/p>\n<p>array2 = np.array([[4], [5], [6]])<\/p>\n<h2><strong>\u4f7f\u7528\u5e7f\u64ad\u673a\u5236\u8fdb\u884c\u76f8\u52a0<\/strong><\/h2>\n<p>result = array1 + array2<\/p>\n<p>print(&quot;\u5e7f\u64ad\u76f8\u52a0\u7ed3\u679c:\\n&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>NumPy\u7684\u77e9\u9635\u8fd0\u7b97<\/strong><\/p>\n<\/p>\n<p><p>NumPy\u4e0d\u4ec5\u652f\u6301\u57fa\u672c\u7684\u9010\u5143\u7d20\u8fd0\u7b97\uff0c\u8fd8\u63d0\u4f9b\u4e86\u77e9\u9635\u8fd0\u7b97\u529f\u80fd\uff0c\u5982\u77e9\u9635\u4e58\u6cd5\u3001\u77e9\u9635\u6c42\u9006\u7b49\u3002\u8fd9\u4e9b\u529f\u80fd\u5728\u6570\u636e\u5206\u6790\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u4e2d\u5e94\u7528\u5e7f\u6cdb\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e24\u4e2a\u77e9\u9635<\/strong><\/h2>\n<p>matrix1 = np.array([[1, 2], [3, 4]])<\/p>\n<p>matrix2 = np.array([[5, 6], [7, 8]])<\/p>\n<h2><strong>\u8fdb\u884c\u77e9\u9635\u4e58\u6cd5<\/strong><\/h2>\n<p>result = np.dot(matrix1, matrix2)<\/p>\n<p>print(&quot;\u77e9\u9635\u4e58\u6cd5\u7ed3\u679c:\\n&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u638c\u63e1NumPy\u7684\u8fd9\u4e9b\u9ad8\u7ea7\u529f\u80fd\uff0c\u53ef\u4ee5\u6781\u5927\u5730\u63d0\u9ad8\u4f60\u7684\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u80fd\u529b\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u548c\u5de5\u5177\u662f\u5173\u952e\uff0cNumPy\u4e3a\u5404\u79cd\u89c4\u6a21\u548c\u590d\u6742\u5ea6\u7684\u6570\u636e\u5904\u7406\u4efb\u52a1\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u7684<code>+<\/code>\u8fd0\u7b97\u7b26\u3001<code>numpy<\/code>\u5e93\u6216\u5217\u8868\u63a8\u5bfc\u5f0f\u3002\u4f7f\u7528<code>+<\/code>\u8fd0\u7b97\u7b26\u53ef\u4ee5\u76f4\u63a5\u5c06\u4e24\u4e2a\u5217\u8868\u5408\u5e76\uff0c\u4f46\u5982\u679c\u662f\u9010\u5143\u7d20\u76f8\u52a0\uff0c\u63a8\u8350\u4f7f\u7528<code>numpy<\/code>\u5e93\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\na = np.array([1, 2, 3])\nb = np.array([4, 5, 6])\nresult = a + b\nprint(result)  # \u8f93\u51fa: [5 7 9]\n<\/code><\/pre>\n<p><strong>\u4f7f\u7528\u4ec0\u4e48\u5e93\u53ef\u4ee5\u63d0\u9ad8Python\u6570\u7ec4\u64cd\u4f5c\u7684\u6548\u7387\uff1f<\/strong><br \/><code>numpy<\/code>\u5e93\u662f\u5904\u7406\u6570\u7ec4\u548c\u77e9\u9635\u7684\u9996\u9009\u5e93\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\u548c\u6570\u5b66\u8ba1\u7b97\u529f\u80fd\u3002\u76f8\u6bd4\u4e8e\u6807\u51c6\u7684Python\u5217\u8868\uff0c<code>numpy<\/code>\u6570\u7ec4\u5728\u6267\u884c\u6570\u5b66\u8fd0\u7b97\u65f6\u901f\u5ea6\u66f4\u5feb\uff0c\u5e76\u4e14\u4f7f\u7528\u66f4\u5c11\u7684\u5185\u5b58\u3002\u901a\u8fc7\u5b89\u88c5<code>numpy<\/code>\u5e93\uff0c\u7528\u6237\u53ef\u4ee5\u4eab\u53d7\u5230\u66f4\u9ad8\u7ea7\u7684\u6570\u7ec4\u64cd\u4f5c\uff0c\u4f8b\u5982\u5e7f\u64ad\u548c\u5411\u91cf\u5316\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u4e0d\u7b49\u957f\u7684\u6570\u7ec4\u76f8\u52a0\uff1f<\/strong><br \/>\u5bf9\u4e8e\u4e0d\u7b49\u957f\u7684\u6570\u7ec4\uff0c\u76f4\u63a5\u76f8\u52a0\u5c06\u4f1a\u5f15\u53d1\u9519\u8bef\u3002\u53ef\u4ee5\u901a\u8fc7\u586b\u5145\u8f83\u77ed\u7684\u6570\u7ec4\u6216\u4f7f\u7528<code>numpy<\/code>\u7684\u5e7f\u64ad\u529f\u80fd\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5c06\u8f83\u77ed\u7684\u6570\u7ec4\u7528\u96f6\u586b\u5145\u81f3\u4e0e\u8f83\u957f\u7684\u6570\u7ec4\u76f8\u540c\u7684\u957f\u5ea6\uff0c\u518d\u8fdb\u884c\u76f8\u52a0\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\na = np.array([1, 2, 3])\nb = np.array([4, 5])\nb = np.pad(b, (0, len(a) - len(b)), &#39;constant&#39;)\nresult = a + b\nprint(result)  # \u8f93\u51fa: [5 7 3]\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5b9e\u73b0\u6570\u7ec4\u76f8\u52a0\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u7684add\u51fd\u6570\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001zip\u51fd\u6570\u3001\u5faa\u73af\u8fed\u4ee3\u7b49\u65b9\u6cd5\u3002Num [&hellip;]","protected":false},"author":3,"featured_media":1003536,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1003527"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1003527"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1003527\/revisions"}],"predecessor-version":[{"id":1003538,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1003527\/revisions\/1003538"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1003536"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1003527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1003527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1003527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}