{"id":1076413,"date":"2025-01-08T11:53:07","date_gmt":"2025-01-08T03:53:07","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1076413.html"},"modified":"2025-01-08T11:53:09","modified_gmt":"2025-01-08T03:53:09","slug":"%e6%ad%a3%e6%80%81%e5%88%86%e5%b8%83%e5%a6%82%e4%bd%95%e6%b1%82%e6%a0%87%e5%87%86%e5%b7%aepython-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1076413.html","title":{"rendered":"\u6b63\u6001\u5206\u5e03\u5982\u4f55\u6c42\u6807\u51c6\u5deepython"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181012\/14298a63-1354-4604-a5a9-cd5975b60977.webp\" alt=\"\u6b63\u6001\u5206\u5e03\u5982\u4f55\u6c42\u6807\u51c6\u5deepython\" \/><\/p>\n<p><p> <strong>\u8981\u7528Python\u6c42\u6b63\u6001\u5206\u5e03\u7684\u6807\u51c6\u5dee\uff0c\u53ef\u4ee5\u4f7f\u7528numpy\u5e93\u7684std()\u51fd\u6570\u3001scipy\u5e93\u7684norm.fit()\u51fd\u6570\u3001\u624b\u52a8\u8ba1\u7b97\u7b49\u65b9\u6cd5\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecdnumpy\u5e93\u7684std()\u51fd\u6570\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528numpy\u5e93\u7684std()\u51fd\u6570<\/p>\n<\/p>\n<p><p>\u4f7f\u7528numpy\u5e93\u8ba1\u7b97\u6807\u51c6\u5dee\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u3002\u9996\u5148\uff0c\u4f7f\u7528numpy\u5e93\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528numpy\u7684std()\u51fd\u6570\u6765\u8ba1\u7b97\u6807\u51c6\u5dee\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u6570\u636e<\/strong><\/h2>\n<p>data = np.random.normal(loc=0, scale=1, size=1000)<\/p>\n<h2><strong>\u8ba1\u7b97\u6807\u51c6\u5dee<\/strong><\/h2>\n<p>std_dev = np.std(data)<\/p>\n<p>print(f&quot;Standard Deviation: {std_dev}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4e8c\u3001\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u6570\u636e<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528numpy\u7684random.normal()\u51fd\u6570\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u6570\u636e\u3002\u8fd9\u4e2a\u51fd\u6570\u6709\u4e09\u4e2a\u53c2\u6570\uff1a\u5747\u503c\uff08loc\uff09\u3001\u6807\u51c6\u5dee\uff08scale\uff09\u548c\u6837\u672c\u6570\u91cf\uff08size\uff09\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u5747\u503c\u4e3a0\uff0c\u6807\u51c6\u5dee\u4e3a1\uff0c\u6837\u672c\u6570\u91cf\u4e3a1000\u7684\u6b63\u6001\u5206\u5e03\u6570\u636e<\/strong><\/h2>\n<p>data = np.random.normal(loc=0, scale=1, size=1000)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4e09\u3001\u8ba1\u7b97\u6807\u51c6\u5dee<\/strong><\/p>\n<\/p>\n<p><p>\u6807\u51c6\u5dee\u7684\u8ba1\u7b97\u516c\u5f0f\u662f\uff1a<\/p>\n<\/p>\n<p><p>[ \\sigma = \\sqrt{\\frac{1}{N}\\sum_{i=1}^{N}(x_i &#8211; \\mu)^2} ]<\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c( \\sigma ) \u662f\u6807\u51c6\u5dee\uff0c( N ) \u662f\u6837\u672c\u6570\u91cf\uff0c( x_i ) \u662f\u7b2ci\u4e2a\u6837\u672c\u6570\u636e\uff0c( \\mu ) \u662f\u6837\u672c\u5747\u503c\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528numpy\u7684std()\u51fd\u6570\u53ef\u4ee5\u5feb\u901f\u8ba1\u7b97\u6807\u51c6\u5dee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">std_dev = np.std(data)<\/p>\n<p>print(f&quot;Standard Deviation: {std_dev}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u56db\u3001numpy\u5e93\u7684\u4f18\u52bf<\/strong><\/p>\n<\/p>\n<p><p>numpy\u5e93\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\u548c\u6570\u5b66\u8fd0\u7b97\u529f\u80fd\uff0c\u4f7f\u5f97\u8ba1\u7b97\u6807\u51c6\u5dee\u53d8\u5f97\u7b80\u5355\u5feb\u6377\u3002numpy\u7684std()\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u5e94\u7528\u4e8e\u6570\u7ec4\uff0c\u907f\u514d\u4e86\u624b\u52a8\u8ba1\u7b97\u7684\u7e41\u7410\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p><strong>\u4e94\u3001\u4e0escipy\u5e93\u7684\u6bd4\u8f83<\/strong><\/p>\n<\/p>\n<p><p>\u867d\u7136numpy\u5e93\u5728\u8ba1\u7b97\u6807\u51c6\u5dee\u65b9\u9762\u975e\u5e38\u65b9\u4fbf\uff0c\u4f46\u6709\u65f6\u4e5f\u53ef\u4ee5\u4f7f\u7528scipy\u5e93\u7684norm.fit()\u51fd\u6570\u6765\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684\u53c2\u6570\uff0c\u5305\u62ec\u5747\u503c\u548c\u6807\u51c6\u5dee\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from scipy.stats import norm<\/p>\n<h2><strong>\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u6570\u636e<\/strong><\/h2>\n<p>data = np.random.normal(loc=0, scale=1, size=1000)<\/p>\n<h2><strong>\u4f7f\u7528norm.fit()\u51fd\u6570\u8ba1\u7b97\u5747\u503c\u548c\u6807\u51c6\u5dee<\/strong><\/h2>\n<p>mu, std_dev = norm.fit(data)<\/p>\n<p>print(f&quot;Mean: {mu}, Standard Deviation: {std_dev}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u516d\u3001\u603b\u7ed3<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u4f7f\u7528numpy\u5e93\u7684std()\u51fd\u6570\u662f\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u6807\u51c6\u5dee\u7684\u6700\u5e38\u89c1\u65b9\u6cd5\u3002\u5b83\u4e0d\u4ec5\u7b80\u5355\u6613\u7528\uff0c\u800c\u4e14\u9ad8\u6548\u3002\u867d\u7136scipy\u5e93\u7684norm.fit()\u51fd\u6570\u4e5f\u53ef\u4ee5\u7528\u6765\u8ba1\u7b97\u6807\u51c6\u5dee\uff0c\u4f46numpy\u5e93\u5728\u5904\u7406\u6570\u7ec4\u548c\u6570\u5b66\u8fd0\u7b97\u65b9\u9762\u66f4\u52a0\u65b9\u4fbf\u5feb\u6377\u3002\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u53ef\u4ee5\u5feb\u901f\u51c6\u786e\u5730\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684\u6807\u51c6\u5dee\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u6b63\u6001\u5206\u5e03\u7684\u6807\u51c6\u5dee\u5728Python\u4e2d\u600e\u4e48\u8ba1\u7b97\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684\u6807\u51c6\u5dee\u3002\u9996\u5148\uff0c\u5bfc\u5165NumPy\u5e93\uff0c\u7136\u540e\u4f7f\u7528<code>numpy.std()<\/code>\u51fd\u6570\u8ba1\u7b97\u6570\u636e\u7684\u6807\u51c6\u5dee\u3002\u5bf9\u4e8e\u6b63\u6001\u5206\u5e03\uff0c\u6807\u51c6\u5dee\u901a\u5e38\u662f\u5728\u7ed9\u5b9a\u6570\u636e\u96c6\u7684\u60c5\u51b5\u4e0b\uff0c\u6839\u636e\u6837\u672c\u7684\u65b9\u5dee\u6765\u63a8\u7b97\u7684\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u7ed8\u5236\u6b63\u6001\u5206\u5e03\u56fe\uff1f<\/strong><br \/>\u8981\u7ed8\u5236\u6b63\u6001\u5206\u5e03\u56fe\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u548cSeaborn\u5e93\u3002\u9996\u5148\uff0c\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u6570\u636e\uff0c\u7136\u540e\u5229\u7528Seaborn\u7684<code>distplot()<\/code>\u6216Matplotlib\u7684<code>plot()<\/code>\u51fd\u6570\u7ed8\u5236\u76f4\u65b9\u56fe\u548c\u66f2\u7ebf\u3002\u901a\u8fc7\u8bbe\u7f6e\u9002\u5f53\u7684\u53c2\u6570\uff0c\u53ef\u4ee5\u76f4\u89c2\u5730\u5c55\u793a\u6b63\u6001\u5206\u5e03\u7684\u5f62\u6001\u53ca\u5176\u6807\u51c6\u5dee\u7684\u5f71\u54cd\u3002<\/p>\n<p><strong>\u5982\u4f55\u9a8c\u8bc1\u4e00\u7ec4\u6570\u636e\u662f\u5426\u7b26\u5408\u6b63\u6001\u5206\u5e03\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u9a8c\u8bc1\u6570\u636e\u7684\u6b63\u6001\u6027\u3002\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\u7ed8\u5236Q-Q\u56fe\uff08Quantile-Quantile Plot\uff09\u548c\u4f7f\u7528Shapiro-Wilk\u68c0\u9a8c\u7b49\u3002\u5728Python\u4e2d\uff0c\u4f7f\u7528SciPy\u5e93\u4e2d\u7684<code>scipy.stats.shapiro()<\/code>\u51fd\u6570\u8fdb\u884cShapiro-Wilk\u68c0\u9a8c\uff0c\u8fd4\u56de\u503c\u53ef\u5e2e\u52a9\u5224\u65ad\u6570\u636e\u662f\u5426\u7b26\u5408\u6b63\u6001\u5206\u5e03\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u7528Python\u6c42\u6b63\u6001\u5206\u5e03\u7684\u6807\u51c6\u5dee\uff0c\u53ef\u4ee5\u4f7f\u7528numpy\u5e93\u7684std()\u51fd\u6570\u3001scipy\u5e93\u7684norm.fit()\u51fd [&hellip;]","protected":false},"author":3,"featured_media":1076422,"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\/1076413"}],"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=1076413"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1076413\/revisions"}],"predecessor-version":[{"id":1076425,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1076413\/revisions\/1076425"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1076422"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1076413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1076413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1076413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}