{"id":960360,"date":"2024-12-27T03:49:01","date_gmt":"2024-12-26T19:49:01","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/960360.html"},"modified":"2024-12-27T03:49:03","modified_gmt":"2024-12-26T19:49:03","slug":"python%e5%a6%82%e4%bd%95%e6%b1%82%e7%9f%a9%e9%98%b5%e8%8c%83%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/960360.html","title":{"rendered":"python\u5982\u4f55\u6c42\u77e9\u9635\u8303\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25102903\/a6565ee1-f2b3-4904-9e03-fc9bc120dcee.webp\" alt=\"python\u5982\u4f55\u6c42\u77e9\u9635\u8303\u6570\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u6c42\u77e9\u9635\u8303\u6570\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528NumPy\u5e93\u5b9e\u73b0\uff0cNumPy\u5e93\u63d0\u4f9b\u4e86\u591a\u79cd\u7528\u4e8e\u8ba1\u7b97\u77e9\u9635\u8303\u6570\u7684\u51fd\u6570\uff0c\u5982<code>numpy.linalg.norm<\/code>\u3002\u901a\u8fc7\u6307\u5b9a\u4e0d\u540c\u7684\u53c2\u6570\uff0c\u53ef\u4ee5\u8ba1\u7b97\u77e9\u9635\u7684\u5404\u79cd\u8303\u6570\uff0c\u5982Frobenius\u8303\u6570\u3001L1\u8303\u6570\u548cL2\u8303\u6570\u7b49\u3002\u6700\u5e38\u7528\u7684\u662fFrobenius\u8303\u6570\uff0c\u56e0\u4e3a\u5b83\u662f\u77e9\u9635\u5143\u7d20\u7684\u5e73\u65b9\u548c\u7684\u5e73\u65b9\u6839\u3002<\/strong><\/p>\n<\/p>\n<p><p><strong>Frobenius\u8303\u6570\u7684\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff1aFrobenius\u8303\u6570\u662f\u8ba1\u7b97\u77e9\u9635\u4e2d\u6240\u6709\u5143\u7d20\u7684\u5e73\u65b9\u548c\u7684\u5e73\u65b9\u6839\uff0c\u8fd9\u53ef\u4ee5\u89c6\u4e3a\u77e9\u9635\u5143\u7d20\u7684\u201c\u6b27\u51e0\u91cc\u5f97\u957f\u5ea6\u201d\u3002\u5728NumPy\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>ord=&#39;fro&#39;<\/code>\u6765\u8ba1\u7b97Frobenius\u8303\u6570\uff0c\u8fd9\u662f\u9ed8\u8ba4\u9009\u9879\u3002Frobenius\u8303\u6570\u9002\u7528\u4e8e\u9700\u8981\u8861\u91cf\u77e9\u9635\u6574\u4f53\u5927\u5c0f\u7684\u60c5\u51b5\uff0c\u5982\u77e9\u9635\u7684\u7a33\u5b9a\u6027\u5206\u6790\u3001\u8bef\u5dee\u4f30\u8ba1\u7b49\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u7406\u89e3\u77e9\u9635\u8303\u6570<\/h3>\n<\/p>\n<p><p>\u77e9\u9635\u8303\u6570\u662f\u7528\u4e8e\u8861\u91cf\u77e9\u9635\u201c\u5927\u5c0f\u201d\u6216\u201c\u957f\u5ea6\u201d\u7684\u4e00\u79cd\u5ea6\u91cf\u3002\u5728\u6570\u5b66\u548c\u5e94\u7528\u9886\u57df\uff0c\u8303\u6570\u88ab\u5e7f\u6cdb\u7528\u4e8e\u5206\u6790\u77e9\u9635\u7684\u6027\u8d28\u3001\u7a33\u5b9a\u6027\u548c\u8bef\u5dee\u7b49\u3002\u4e0d\u540c\u7684\u8303\u6570\u5177\u6709\u4e0d\u540c\u7684\u5b9a\u4e49\u548c\u7528\u9014\uff0c\u9009\u62e9\u9002\u5f53\u7684\u8303\u6570\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u95ee\u9898\u548c\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5e38\u89c1\u7684\u77e9\u9635\u8303\u6570\u7c7b\u578b<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>Frobenius\u8303\u6570<\/strong>\uff1a\u8ba1\u7b97\u77e9\u9635\u4e2d\u6240\u6709\u5143\u7d20\u7684\u5e73\u65b9\u548c\u7684\u5e73\u65b9\u6839\uff0c\u9002\u5408\u7528\u4e8e\u77e9\u9635\u7684\u6574\u4f53\u5927\u5c0f\u6d4b\u91cf\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>L1\u8303\u6570<\/strong>\uff1a\u77e9\u9635\u5404\u5217\u5411\u91cf\u7684\u7edd\u5bf9\u503c\u4e4b\u548c\u7684\u6700\u5927\u503c\uff0c\u901a\u5e38\u7528\u4e8e\u7a00\u758f\u6027\u5206\u6790\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>L2\u8303\u6570\uff08\u8c31\u8303\u6570\uff09<\/strong>\uff1a\u77e9\u9635\u7684\u6700\u5927\u5947\u5f02\u503c\uff0c\u5e38\u7528\u4e8e\u7a33\u5b9a\u6027\u5206\u6790\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u65e0\u7a77\u8303\u6570<\/strong>\uff1a\u77e9\u9635\u5404\u884c\u5143\u7d20\u7edd\u5bf9\u503c\u4e4b\u548c\u7684\u6700\u5927\u503c\uff0c\u9002\u5408\u4e8e\u884c\u7684\u6700\u5927\u5f71\u54cd\u5206\u6790\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h4>2\u3001\u5e94\u7528\u573a\u666f<\/h4>\n<\/p>\n<p><p>\u5728<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u3001\u6570\u636e\u5206\u6790\u548c\u8ba1\u7b97\u6570\u5b66\u7b49\u9886\u57df\uff0c\u77e9\u9635\u8303\u6570\u7528\u4e8e\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u8bef\u5dee\u5206\u6790<\/strong>\uff1a\u8861\u91cf\u9884\u6d4b\u503c\u4e0e\u771f\u5b9e\u503c\u4e4b\u95f4\u7684\u504f\u5dee\u3002<\/li>\n<li><strong>\u7a33\u5b9a\u6027\u5206\u6790<\/strong>\uff1a\u8bc4<a href=\"https:\/\/docs.pingcode.com\/agile\/project-management\/estimation\" target=\"_blank\">\u4f30\u7b97<\/a>\u6cd5\u5bf9\u8f93\u5165\u6270\u52a8\u7684\u654f\u611f\u6027\u3002<\/li>\n<li><strong>\u77e9\u9635\u5206\u89e3<\/strong>\uff1a\u5982PCA\u3001SVD\u7b49\u65b9\u6cd5\u4e2d\u7684\u77e9\u9635\u903c\u8fd1\u3002<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001NumPy\u5e93\u4e2d\u7684\u77e9\u9635\u8303\u6570\u8ba1\u7b97<\/h3>\n<\/p>\n<p><p>Python\u4e2d\u7684NumPy\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u7ebf\u6027\u4ee3\u6570\u529f\u80fd\uff0c\u5176\u4e2d<code>numpy.linalg.norm<\/code>\u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u5411\u91cf\u548c\u77e9\u9635\u7684\u8303\u6570\u3002\u8be5\u51fd\u6570\u7075\u6d3b\u4e14\u6613\u4e8e\u4f7f\u7528\uff0c\u53ef\u6839\u636e\u9700\u6c42\u8ba1\u7b97\u4e0d\u540c\u7c7b\u578b\u7684\u8303\u6570\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u57fa\u672c\u7528\u6cd5<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u77e9\u9635<\/strong><\/h2>\n<p>A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])<\/p>\n<h2><strong>\u8ba1\u7b97Frobenius\u8303\u6570<\/strong><\/h2>\n<p>frobenius_norm = np.linalg.norm(A, &#39;fro&#39;)<\/p>\n<p>print(&quot;Frobenius\u8303\u6570:&quot;, frobenius_norm)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>numpy.linalg.norm<\/code>\u51fd\u6570\u901a\u8fc7\u8bbe\u7f6e<code>ord=&#39;fro&#39;<\/code>\u8ba1\u7b97\u77e9\u9635A\u7684Frobenius\u8303\u6570\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u8ba1\u7b97\u5176\u4ed6\u7c7b\u578b\u7684\u8303\u6570<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u6539\u53d8<code>ord<\/code>\u53c2\u6570\u7684\u503c\uff0c\u53ef\u4ee5\u8ba1\u7b97\u4e0d\u540c\u7684\u77e9\u9635\u8303\u6570\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97L1\u8303\u6570\u548c\u65e0\u7a77\u8303\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97L1\u8303\u6570<\/p>\n<p>l1_norm = np.linalg.norm(A, 1)<\/p>\n<p>print(&quot;L1\u8303\u6570:&quot;, l1_norm)<\/p>\n<h2><strong>\u8ba1\u7b97\u65e0\u7a77\u8303\u6570<\/strong><\/h2>\n<p>inf_norm = np.linalg.norm(A, np.inf)<\/p>\n<p>print(&quot;\u65e0\u7a77\u8303\u6570:&quot;, inf_norm)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u6df1\u5165\u7406\u89e3Frobenius\u8303\u6570<\/h3>\n<\/p>\n<p><p>Frobenius\u8303\u6570\u662f\u77e9\u9635\u8303\u6570\u4e2d\u6700\u5e38\u7528\u7684\u4e00\u79cd\uff0c\u56e0\u4e3a\u5b83\u662f\u77e9\u9635\u5143\u7d20\u7684\u5e73\u65b9\u548c\u7684\u5e73\u65b9\u6839\uff0c\u7c7b\u4f3c\u4e8e\u5411\u91cf\u7684\u6b27\u51e0\u91cc\u5f97\u8303\u6570\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8ba1\u7b97\u516c\u5f0f<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4e00\u4e2am x n\u77e9\u9635A\uff0cFrobenius\u8303\u6570\u7684\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1a<\/p>\n<\/p>\n<p><p>[ |A|<em>F = \\sqrt{\\sum<\/em>{i=1}^{m} \\sum_{j=1}^{n} |a_{ij}|^2} ]<\/p>\n<\/p>\n<p><p>\u8fd9\u79cd\u8ba1\u7b97\u65b9\u5f0f\u53cd\u6620\u4e86\u77e9\u9635\u4e2d\u6240\u6709\u5143\u7d20\u7684\u96c6\u4f53\u8d21\u732e\u3002<\/p>\n<\/p>\n<p><h4>2\u3001Frobenius\u8303\u6570\u7684\u6027\u8d28<\/h4>\n<\/p>\n<ul>\n<li><strong>\u6b63\u5b9a\u6027<\/strong>\uff1a(|A|_F \\geq 0)\uff0c\u4e14\u5f53\u4e14\u4ec5\u5f53A\u4e3a\u96f6\u77e9\u9635\u65f6\uff0c(|A|_F = 0)\u3002<\/li>\n<li><strong>\u9f50\u6b21\u6027<\/strong>\uff1a\u5bf9\u4e8e\u4efb\u610f\u6807\u91cf(\\alpha)\uff0c(|\\alpha A|_F = |\\alpha| |A|_F)\u3002<\/li>\n<li><strong>\u4e09\u89d2\u4e0d\u7b49\u5f0f<\/strong>\uff1a(|A + B|_F \\leq |A|_F + |B|_F)\u3002<\/li>\n<\/ul>\n<p><p>\u8fd9\u4e9b\u6027\u8d28\u4f7f\u5f97Frobenius\u8303\u6570\u5728\u7406\u8bba\u7814\u7a76\u548c\u5b9e\u8df5\u5e94\u7528\u4e2d\u5177\u6709\u826f\u597d\u7684\u6570\u5b66\u7279\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5176\u4ed6\u8303\u6570\u7684\u4f7f\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u867d\u7136Frobenius\u8303\u6570\u662f\u6700\u5e38\u7528\u7684\uff0c\u4f46\u5176\u4ed6\u8303\u6570\u5728\u7279\u5b9a\u573a\u666f\u4e2d\u4e5f\u6709\u5176\u4f18\u52bf\u3002<\/p>\n<\/p>\n<p><h4>1\u3001L1\u8303\u6570<\/h4>\n<\/p>\n<p><p>L1\u8303\u6570\u5e38\u7528\u4e8e\u7a00\u758f\u6027\u5206\u6790\u548c\u6b63\u5219\u5316\u3002\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0cL1\u6b63\u5219\u5316\uff08Lasso\u56de\u5f52\uff09\u901a\u8fc7\u6700\u5c0f\u5316L1\u8303\u6570\u6765\u4ea7\u751f\u7a00\u758f\u89e3\uff0c\u4ece\u800c\u5b9e\u73b0\u7279\u5f81\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># Lasso\u56de\u5f52\u793a\u4f8b<\/p>\n<p>from sklearn.linear_model import Lasso<\/p>\n<p>X = np.array([[1, 2], [2, 3], [3, 4]])<\/p>\n<p>y = np.array([1, 2, 3])<\/p>\n<p>lasso = Lasso(alpha=0.1)<\/p>\n<p>lasso.fit(X, y)<\/p>\n<p>print(&quot;Lasso\u7cfb\u6570:&quot;, lasso.coef_)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001L2\u8303\u6570\uff08\u8c31\u8303\u6570\uff09<\/h4>\n<\/p>\n<p><p>L2\u8303\u6570\u7528\u4e8e\u7a33\u5b9a\u6027\u5206\u6790\u548c\u6b63\u5219\u5316\u3002Ridge\u56de\u5f52\u901a\u8fc7\u6700\u5c0f\u5316L2\u8303\u6570\u6765\u9632\u6b62\u8fc7\u62df\u5408\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># Ridge\u56de\u5f52\u793a\u4f8b<\/p>\n<p>from sklearn.linear_model import Ridge<\/p>\n<p>ridge = Ridge(alpha=0.1)<\/p>\n<p>ridge.fit(X, y)<\/p>\n<p>print(&quot;Ridge\u7cfb\u6570:&quot;, ridge.coef_)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u77e9\u9635\u8303\u6570\u5728\u5b9e\u8df5\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u77e9\u9635\u8303\u6570\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u7b97\u6cd5\u7684\u6027\u80fd\u548c\u7ed3\u679c\u7684\u53ef\u9760\u6027\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8bef\u5dee\u4f30\u8ba1<\/h4>\n<\/p>\n<p><p>\u5728\u6570\u503c\u5206\u6790\u4e2d\uff0c\u77e9\u9635\u8303\u6570\u7528\u4e8e\u8bc4\u4f30\u7b97\u6cd5\u7684\u8bef\u5dee\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97\u77e9\u9635\u8fd1\u4f3c\u503c\u4e0e\u771f\u5b9e\u503c\u4e4b\u95f4\u7684Frobenius\u8303\u6570\u5dee\u5f02\uff0c\u7528\u4e8e\u8bc4\u4f30\u903c\u8fd1\u7684\u8d28\u91cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u8bef\u5dee<\/p>\n<p>B = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 8]])<\/p>\n<p>error = np.linalg.norm(A - B, &#39;fro&#39;)<\/p>\n<p>print(&quot;\u8bef\u5dee:&quot;, error)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7a33\u5b9a\u6027\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u5728\u6570\u503c\u7b97\u6cd5\u4e2d\uff0c\u77e9\u9635\u8303\u6570\u7528\u4e8e\u5206\u6790\u7b97\u6cd5\u5bf9\u8f93\u5165\u53d8\u5316\u7684\u654f\u611f\u6027\u3002\u4f8b\u5982\uff0c\u901a\u8fc7\u8ba1\u7b97\u8f93\u5165\u77e9\u9635\u7684L2\u8303\u6570\uff0c\u53ef\u4ee5\u8bc4\u4f30\u7b97\u6cd5\u5728\u4e0d\u540c\u6761\u4ef6\u4e0b\u7684\u8868\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u7a33\u5b9a\u6027\u5206\u6790\u793a\u4f8b<\/p>\n<p>perturbation = np.array([[0.1, 0.2, 0.1], [0.1, 0.1, 0.1], [0.1, 0.1, 0.1]])<\/p>\n<p>stability = np.linalg.norm(perturbation, 2)<\/p>\n<p>print(&quot;\u7a33\u5b9a\u6027:&quot;, stability)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u77e9\u9635\u8303\u6570\u662f\u7ebf\u6027\u4ee3\u6570\u4e2d\u7684\u91cd\u8981\u5de5\u5177\uff0c\u63d0\u4f9b\u4e86\u8861\u91cf\u77e9\u9635\u5927\u5c0f\u548c\u5f71\u54cd\u529b\u7684\u65b9\u6cd5\u3002\u5728Python\u4e2d\uff0cNumPy\u5e93\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u51fd\u6570\u6765\u8ba1\u7b97\u5404\u79cd\u77e9\u9635\u8303\u6570\uff0c\u6ee1\u8db3\u4e0d\u540c\u7684\u5e94\u7528\u9700\u6c42\u3002\u901a\u8fc7\u7406\u89e3\u548c\u5e94\u7528\u77e9\u9635\u8303\u6570\uff0c\u53ef\u4ee5\u6709\u6548\u5206\u6790\u7b97\u6cd5\u7684\u8bef\u5dee\u548c\u7a33\u5b9a\u6027\uff0c\u63d0\u9ad8\u6570\u636e\u5206\u6790\u548c\u673a\u5668\u5b66\u4e60\u7684\u7ed3\u679c\u8d28\u91cf\u3002\u5728\u9009\u62e9\u8303\u6570\u65f6\uff0c\u5e94\u6839\u636e\u5177\u4f53\u95ee\u9898\u548c\u5e94\u7528\u573a\u666f\u4f5c\u51fa\u5408\u7406\u9009\u62e9\uff0c\u4ee5\u4fbf\u5145\u5206\u5229\u7528\u8303\u6570\u7684\u7279\u6027\u6765\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u4ec0\u4e48\u662f\u77e9\u9635\u8303\u6570\uff0c\u4e3a\u4ec0\u4e48\u5728Python\u4e2d\u8ba1\u7b97\u5b83\u5f88\u91cd\u8981\uff1f<\/strong><br \/>\u77e9\u9635\u8303\u6570\u662f\u7528\u6765\u8861\u91cf\u77e9\u9635\u5927\u5c0f\u6216\u590d\u6742\u5ea6\u7684\u4e00\u4e2a\u6307\u6807\u3002\u5b83\u5728\u6570\u503c\u5206\u6790\u3001\u673a\u5668\u5b66\u4e60\u548c\u4f18\u5316\u7b49\u9886\u57df\u4e2d\u8d77\u7740\u5173\u952e\u4f5c\u7528\u3002\u8ba1\u7b97\u77e9\u9635\u8303\u6570\u53ef\u4ee5\u5e2e\u52a9\u7406\u89e3\u77e9\u9635\u7684\u6027\u8d28\uff0c\u4f8b\u5982\u7a33\u5b9a\u6027\u548c\u4e00\u81f4\u6027\u3002\u5728Python\u4e2d\uff0c\u4f7f\u7528NumPy\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u8ba1\u7b97\u5404\u79cd\u7c7b\u578b\u7684\u77e9\u9635\u8303\u6570\uff0c\u5982L1\u8303\u6570\u3001L2\u8303\u6570\u548c\u65e0\u7a77\u8303\u6570\u7b49\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u4f7f\u7528\u54ea\u4e2a\u5e93\u8ba1\u7b97\u77e9\u9635\u8303\u6570\u6700\u65b9\u4fbf\uff1f<\/strong><br \/>NumPy\u662f\u8ba1\u7b97\u77e9\u9635\u8303\u6570\u7684\u9996\u9009\u5e93\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u5b9e\u73b0\u548c\u4e30\u5bcc\u7684\u529f\u80fd\u3002\u901a\u8fc7NumPy\u7684<code>numpy.linalg.norm()<\/code>\u51fd\u6570\uff0c\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u5730\u8ba1\u7b97\u4e0d\u540c\u7c7b\u578b\u7684\u8303\u6570\u3002\u5176\u4ed6\u5e93\u5982SciPy\u4e5f\u63d0\u4f9b\u7c7b\u4f3c\u7684\u529f\u80fd\uff0c\u9002\u7528\u4e8e\u66f4\u590d\u6742\u7684\u6570\u5b66\u8ba1\u7b97\u9700\u6c42\u3002<\/p>\n<p><strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u77e9\u9635\u8303\u6570\u7c7b\u578b\uff1f<\/strong><br \/>\u9009\u62e9\u77e9\u9635\u8303\u6570\u7c7b\u578b\u901a\u5e38\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u3002L1\u8303\u6570\u9002\u5408\u7528\u4e8e\u7a00\u758f\u6570\u636e\u7684\u5206\u6790\uff0c\u800cL2\u8303\u6570\u5e38\u7528\u4e8e\u673a\u5668\u5b66\u4e60\u4e2d\u7684\u4f18\u5316\u95ee\u9898\uff0c\u56e0\u4e3a\u5b83\u5bf9\u5f02\u5e38\u503c\u7684\u654f\u611f\u6027\u8f83\u4f4e\u3002\u65e0\u7a77\u8303\u6570\u5728\u67d0\u4e9b\u7ebf\u6027\u4ee3\u6570\u95ee\u9898\u4e2d\u4e5f\u5341\u5206\u6709\u7528\u3002\u4e86\u89e3\u4e0d\u540c\u8303\u6570\u7684\u7279\u6027\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u5728\u7279\u5b9a\u573a\u666f\u4e2d\u505a\u51fa\u66f4\u597d\u7684\u9009\u62e9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u6c42\u77e9\u9635\u8303\u6570\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528NumPy\u5e93\u5b9e\u73b0\uff0cNumPy\u5e93\u63d0\u4f9b\u4e86\u591a\u79cd\u7528\u4e8e\u8ba1\u7b97\u77e9\u9635\u8303\u6570\u7684\u51fd\u6570\uff0c\u5982nu [&hellip;]","protected":false},"author":3,"featured_media":960369,"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\/960360"}],"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=960360"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/960360\/revisions"}],"predecessor-version":[{"id":960373,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/960360\/revisions\/960373"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/960369"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=960360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=960360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=960360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}