{"id":1053041,"date":"2024-12-31T14:30:22","date_gmt":"2024-12-31T06:30:22","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1053041.html"},"modified":"2024-12-31T14:30:24","modified_gmt":"2024-12-31T06:30:24","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e6%b1%82%e6%ad%a3%e6%80%81%e5%88%86%e5%b8%83%e7%9a%84%e5%80%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1053041.html","title":{"rendered":"Python\u4e2d\u5982\u4f55\u6c42\u6b63\u6001\u5206\u5e03\u7684\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/6a1a9273-9900-4938-9d45-ff8d336f5f26.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"Python\u4e2d\u5982\u4f55\u6c42\u6b63\u6001\u5206\u5e03\u7684\u503c\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u6c42\u6b63\u6001\u5206\u5e03\u7684\u503c\u53ef\u4ee5\u4f7f\u7528SciPy\u5e93\u3001NumPy\u5e93\u3001Matplotlib\u5e93<\/strong>\u3002SciPy\u5e93\u63d0\u4f9b\u4e86\u4e13\u95e8\u7684\u51fd\u6570\u6765\u751f\u6210\u6b63\u6001\u5206\u5e03\u4ee5\u53ca\u8ba1\u7b97\u5176\u6982\u7387\u5bc6\u5ea6\u51fd\u6570\uff08PDF\uff09\u548c\u7d2f\u79ef\u5206\u5e03\u51fd\u6570\uff08CDF\uff09\u3002NumPy\u5e93\u7528\u4e8e\u751f\u6210\u968f\u673a\u6570\u548c\u6570\u7ec4\u64cd\u4f5c\uff0cMatplotlib\u5e93\u5219\u7528\u4e8e\u6570\u636e\u7684\u53ef\u89c6\u5316\u3002<strong>\u4f7f\u7528SciPy.stats\u6a21\u5757\u4e2d\u7684norm\u51fd\u6570<\/strong>\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684\u76f8\u5173\u503c\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u5c55\u5f00\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5e93\u6765\u8ba1\u7b97\u548c\u53ef\u89c6\u5316\u6b63\u6001\u5206\u5e03\u7684\u503c\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001SciPy\u5e93\u4e2d\u7684\u6b63\u6001\u5206\u5e03<\/p>\n<\/p>\n<p><p>SciPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u5305\u542b\u4e86\u8bb8\u591a\u7edf\u8ba1\u5de5\u5177\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528SciPy.stats\u6a21\u5757\u4e2d\u7684norm\u51fd\u6570\u6765\u751f\u6210\u6b63\u6001\u5206\u5e03\u5e76\u8ba1\u7b97\u76f8\u5173\u503c\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u751f\u6210\u6b63\u6001\u5206\u5e03<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5SciPy\u5e93\u3002\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5SciPy\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install scipy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u751f\u6210\u6b63\u6001\u5206\u5e03\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>import scipy.stats as stats<\/p>\n<h2><strong>\u5b9a\u4e49\u5747\u503c\u548c\u6807\u51c6\u5dee<\/strong><\/h2>\n<p>mean = 0<\/p>\n<p>std_dev = 1<\/p>\n<h2><strong>\u751f\u6210\u6b63\u6001\u5206\u5e03<\/strong><\/h2>\n<p>normal_dist = stats.norm(loc=mean, scale=std_dev)<\/p>\n<h2><strong>\u751f\u62101000\u4e2a\u6b63\u6001\u5206\u5e03\u7684\u6837\u672c<\/strong><\/h2>\n<p>samples = normal_dist.rvs(size=1000)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u5747\u503c\u4e3a0\uff0c\u6807\u51c6\u5dee\u4e3a1\u7684\u6b63\u6001\u5206\u5e03\uff0c\u5e76\u751f\u6210\u4e861000\u4e2a\u6b63\u6001\u5206\u5e03\u7684\u6837\u672c\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u8ba1\u7b97\u6982\u7387\u5bc6\u5ea6\u51fd\u6570\uff08PDF\uff09<\/h3>\n<\/p>\n<p><p>\u6982\u7387\u5bc6\u5ea6\u51fd\u6570\uff08PDF\uff09\u63cf\u8ff0\u4e86\u5728\u7279\u5b9a\u70b9\u5904\u51fa\u73b0\u67d0\u4e2a\u503c\u7684\u6982\u7387\u5bc6\u5ea6\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528SciPy.stats\u6a21\u5757\u4e2d\u7684pdf\u51fd\u6570\u6765\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684PDF\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u67d0\u4e2a\u503c\u7684\u6982\u7387\u5bc6\u5ea6<\/p>\n<p>x = 0<\/p>\n<p>pdf_value = normal_dist.pdf(x)<\/p>\n<p>print(f&quot;PDF at x={x}: {pdf_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u8ba1\u7b97\u4e86\u6b63\u6001\u5206\u5e03\u5728x=0\u5904\u7684\u6982\u7387\u5bc6\u5ea6\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u8ba1\u7b97\u7d2f\u79ef\u5206\u5e03\u51fd\u6570\uff08CDF\uff09<\/h3>\n<\/p>\n<p><p>\u7d2f\u79ef\u5206\u5e03\u51fd\u6570\uff08CDF\uff09\u63cf\u8ff0\u4e86\u968f\u673a\u53d8\u91cf\u5728\u67d0\u4e2a\u503c\u5c0f\u4e8e\u7b49\u4e8e\u7ed9\u5b9a\u503c\u7684\u6982\u7387\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528SciPy.stats\u6a21\u5757\u4e2d\u7684cdf\u51fd\u6570\u6765\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684CDF\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u67d0\u4e2a\u503c\u7684\u7d2f\u79ef\u5206\u5e03\u51fd\u6570<\/p>\n<p>x = 0<\/p>\n<p>cdf_value = normal_dist.cdf(x)<\/p>\n<p>print(f&quot;CDF at x={x}: {cdf_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u8ba1\u7b97\u4e86\u6b63\u6001\u5206\u5e03\u5728x=0\u5904\u7684\u7d2f\u79ef\u6982\u7387\u3002<\/p>\n<\/p>\n<p><h3>4\u3001\u53ef\u89c6\u5316\u6b63\u6001\u5206\u5e03<\/h3>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u53ef\u89c6\u5316\u6b63\u6001\u5206\u5e03\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5Matplotlib\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u751f\u6210x\u8f74\u7684\u503c<\/strong><\/h2>\n<p>x = np.linspace(-4, 4, 1000)<\/p>\n<h2><strong>\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684PDF<\/strong><\/h2>\n<p>pdf_values = normal_dist.pdf(x)<\/p>\n<h2><strong>\u7ed8\u5236\u6b63\u6001\u5206\u5e03\u7684PDF<\/strong><\/h2>\n<p>plt.plot(x, pdf_values, label=&#39;PDF&#39;)<\/p>\n<p>plt.title(&#39;Normal Distribution&#39;)<\/p>\n<p>plt.xlabel(&#39;x&#39;)<\/p>\n<p>plt.ylabel(&#39;Probability Density&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4ece-4\u52304\u7684x\u8f74\u503c\uff0c\u5e76\u8ba1\u7b97\u4e86\u6bcf\u4e2a\u70b9\u7684PDF\u503c\uff0c\u7136\u540e\u4f7f\u7528Matplotlib\u7ed8\u5236\u4e86\u6b63\u6001\u5206\u5e03\u7684PDF\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001NumPy\u5e93\u4e2d\u7684\u6b63\u6001\u5206\u5e03<\/p>\n<\/p>\n<p><p>NumPy\u5e93\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u6570\u503c\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u751f\u6210\u968f\u673a\u6570\u548c\u6570\u7ec4\u64cd\u4f5c\u7684\u529f\u80fd\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u4e2d\u7684random\u6a21\u5757\u6765\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u968f\u673a\u6570\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u751f\u6210\u6b63\u6001\u5206\u5e03<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5NumPy\u5e93\u3002\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5NumPy\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u751f\u6210\u6b63\u6001\u5206\u5e03\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u5b9a\u4e49\u5747\u503c\u548c\u6807\u51c6\u5dee<\/strong><\/h2>\n<p>mean = 0<\/p>\n<p>std_dev = 1<\/p>\n<h2><strong>\u751f\u62101000\u4e2a\u6b63\u6001\u5206\u5e03\u7684\u6837\u672c<\/strong><\/h2>\n<p>samples = np.random.normal(loc=mean, scale=std_dev, size=1000)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u5747\u503c\u4e3a0\uff0c\u6807\u51c6\u5dee\u4e3a1\u7684\u6b63\u6001\u5206\u5e03\uff0c\u5e76\u751f\u6210\u4e861000\u4e2a\u6b63\u6001\u5206\u5e03\u7684\u6837\u672c\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u8ba1\u7b97\u6982\u7387\u5bc6\u5ea6\u51fd\u6570\uff08PDF\uff09<\/h3>\n<\/p>\n<p><p>NumPy\u5e93\u6ca1\u6709\u76f4\u63a5\u63d0\u4f9b\u8ba1\u7b97PDF\u7684\u51fd\u6570\uff0c\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528SciPy\u5e93\u6765\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684PDF\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import scipy.stats as stats<\/p>\n<h2><strong>\u8ba1\u7b97\u67d0\u4e2a\u503c\u7684\u6982\u7387\u5bc6\u5ea6<\/strong><\/h2>\n<p>x = 0<\/p>\n<p>pdf_value = stats.norm.pdf(x, loc=mean, scale=std_dev)<\/p>\n<p>print(f&quot;PDF at x={x}: {pdf_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528SciPy\u5e93\u8ba1\u7b97\u4e86\u6b63\u6001\u5206\u5e03\u5728x=0\u5904\u7684\u6982\u7387\u5bc6\u5ea6\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u8ba1\u7b97\u7d2f\u79ef\u5206\u5e03\u51fd\u6570\uff08CDF\uff09<\/h3>\n<\/p>\n<p><p>\u540c\u6837\uff0cNumPy\u5e93\u6ca1\u6709\u76f4\u63a5\u63d0\u4f9b\u8ba1\u7b97CDF\u7684\u51fd\u6570\uff0c\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528SciPy\u5e93\u6765\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684CDF\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import scipy.stats as stats<\/p>\n<h2><strong>\u8ba1\u7b97\u67d0\u4e2a\u503c\u7684\u7d2f\u79ef\u5206\u5e03\u51fd\u6570<\/strong><\/h2>\n<p>x = 0<\/p>\n<p>cdf_value = stats.norm.cdf(x, loc=mean, scale=std_dev)<\/p>\n<p>print(f&quot;CDF at x={x}: {cdf_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528SciPy\u5e93\u8ba1\u7b97\u4e86\u6b63\u6001\u5206\u5e03\u5728x=0\u5904\u7684\u7d2f\u79ef\u6982\u7387\u3002<\/p>\n<\/p>\n<p><h3>4\u3001\u53ef\u89c6\u5316\u6b63\u6001\u5206\u5e03<\/h3>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u53ef\u89c6\u5316\u6b63\u6001\u5206\u5e03\u3002\u4ee5\u4e0b\u4ee3\u7801\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u751f\u6210x\u8f74\u7684\u503c<\/strong><\/h2>\n<p>x = np.linspace(-4, 4, 1000)<\/p>\n<h2><strong>\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684PDF<\/strong><\/h2>\n<p>pdf_values = stats.norm.pdf(x, loc=mean, scale=std_dev)<\/p>\n<h2><strong>\u7ed8\u5236\u6b63\u6001\u5206\u5e03\u7684PDF<\/strong><\/h2>\n<p>plt.plot(x, pdf_values, label=&#39;PDF&#39;)<\/p>\n<p>plt.title(&#39;Normal Distribution&#39;)<\/p>\n<p>plt.xlabel(&#39;x&#39;)<\/p>\n<p>plt.ylabel(&#39;Probability Density&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4ece-4\u52304\u7684x\u8f74\u503c\uff0c\u5e76\u8ba1\u7b97\u4e86\u6bcf\u4e2a\u70b9\u7684PDF\u503c\uff0c\u7136\u540e\u4f7f\u7528Matplotlib\u7ed8\u5236\u4e86\u6b63\u6001\u5206\u5e03\u7684PDF\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u5b9e\u4f8b\u5e94\u7528<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u4f7f\u7528\u6b63\u6001\u5206\u5e03\uff0c\u6211\u4eec\u5c06\u4e3e\u4e00\u4e2a\u5b9e\u9645\u7684\u4f8b\u5b50\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u7ec4\u5b66\u751f\u7684\u8003\u8bd5\u6210\u7ee9\u6570\u636e\uff0c\u6211\u4eec\u5e0c\u671b\u5206\u6790\u8fd9\u4e9b\u6210\u7ee9\u7684\u5206\u5e03\u60c5\u51b5\uff0c\u5e76\u8ba1\u7b97\u67d0\u4e2a\u5206\u6570\u8303\u56f4\u5185\u7684\u5b66\u751f\u6bd4\u4f8b\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u751f\u6210\u6210\u7ee9\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u751f\u6210\u4e00\u7ec4\u6a21\u62df\u7684\u5b66\u751f\u6210\u7ee9\u6570\u636e\uff0c\u5047\u8bbe\u6210\u7ee9\u670d\u4ece\u6b63\u6001\u5206\u5e03\uff0c\u5747\u503c\u4e3a75\uff0c\u6807\u51c6\u5dee\u4e3a10\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u5b9a\u4e49\u5747\u503c\u548c\u6807\u51c6\u5dee<\/strong><\/h2>\n<p>mean = 75<\/p>\n<p>std_dev = 10<\/p>\n<h2><strong>\u751f\u62101000\u4e2a\u5b66\u751f\u6210\u7ee9\u7684\u6837\u672c<\/strong><\/h2>\n<p>scores = np.random.normal(loc=mean, scale=std_dev, size=1000)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u8ba1\u7b97\u67d0\u4e2a\u5206\u6570\u7684\u6982\u7387\u5bc6\u5ea6<\/h3>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u5e0c\u671b\u8ba1\u7b97\u67d0\u4e2a\u5206\u6570\uff08\u4f8b\u598280\u5206\uff09\u7684\u6982\u7387\u5bc6\u5ea6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import scipy.stats as stats<\/p>\n<h2><strong>\u8ba1\u7b9780\u5206\u7684\u6982\u7387\u5bc6\u5ea6<\/strong><\/h2>\n<p>score = 80<\/p>\n<p>pdf_value = stats.norm.pdf(score, loc=mean, scale=std_dev)<\/p>\n<p>print(f&quot;PDF at score={score}: {pdf_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u8ba1\u7b97\u67d0\u4e2a\u5206\u6570\u8303\u56f4\u5185\u7684\u5b66\u751f\u6bd4\u4f8b<\/h3>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u5e0c\u671b\u8ba1\u7b9770\u5206\u523080\u5206\u8303\u56f4\u5185\u7684\u5b66\u751f\u6bd4\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b9770\u5206\u548c80\u5206\u7684\u7d2f\u79ef\u5206\u5e03\u51fd\u6570\u503c<\/p>\n<p>cdf_70 = stats.norm.cdf(70, loc=mean, scale=std_dev)<\/p>\n<p>cdf_80 = stats.norm.cdf(80, loc=mean, scale=std_dev)<\/p>\n<h2><strong>\u8ba1\u7b9770\u5206\u523080\u5206\u8303\u56f4\u5185\u7684\u5b66\u751f\u6bd4\u4f8b<\/strong><\/h2>\n<p>proportion = cdf_80 - cdf_70<\/p>\n<p>print(f&quot;Proportion of students scoring between 70 and 80: {proportion}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4\u3001\u53ef\u89c6\u5316\u6210\u7ee9\u5206\u5e03<\/h3>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u6211\u4eec\u4f7f\u7528Matplotlib\u5e93\u53ef\u89c6\u5316\u5b66\u751f\u6210\u7ee9\u7684\u5206\u5e03\u60c5\u51b5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u751f\u6210x\u8f74\u7684\u503c<\/strong><\/h2>\n<p>x = np.linspace(40, 110, 1000)<\/p>\n<h2><strong>\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684PDF<\/strong><\/h2>\n<p>pdf_values = stats.norm.pdf(x, loc=mean, scale=std_dev)<\/p>\n<h2><strong>\u7ed8\u5236\u6b63\u6001\u5206\u5e03\u7684PDF<\/strong><\/h2>\n<p>plt.plot(x, pdf_values, label=&#39;PDF&#39;)<\/p>\n<p>plt.title(&#39;Student Scores Distribution&#39;)<\/p>\n<p>plt.xlabel(&#39;Score&#39;)<\/p>\n<p>plt.ylabel(&#39;Probability Density&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4ece40\u5230110\u7684x\u8f74\u503c\uff0c\u5e76\u8ba1\u7b97\u4e86\u6bcf\u4e2a\u70b9\u7684PDF\u503c\uff0c\u7136\u540e\u4f7f\u7528Matplotlib\u7ed8\u5236\u4e86\u5b66\u751f\u6210\u7ee9\u7684\u5206\u5e03\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u6210\u529f\u5730\u751f\u6210\u4e86\u6b63\u6001\u5206\u5e03\u7684\u5b66\u751f\u6210\u7ee9\u6570\u636e\uff0c\u5e76\u8ba1\u7b97\u4e86\u67d0\u4e2a\u5206\u6570\u7684\u6982\u7387\u5bc6\u5ea6\u548c\u67d0\u4e2a\u5206\u6570\u8303\u56f4\u5185\u7684\u5b66\u751f\u6bd4\u4f8b\uff0c\u6700\u540e\u53ef\u89c6\u5316\u4e86\u5b66\u751f\u6210\u7ee9\u7684\u5206\u5e03\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u6c42\u6b63\u6001\u5206\u5e03\u7684\u503c\u53ef\u4ee5\u4f7f\u7528SciPy\u5e93\u3001NumPy\u5e93\u548cMatplotlib\u5e93\u3002SciPy\u5e93\u63d0\u4f9b\u4e86\u751f\u6210\u6b63\u6001\u5206\u5e03\u548c\u8ba1\u7b97\u6982\u7387\u5bc6\u5ea6\u51fd\u6570\uff08PDF\uff09\u53ca\u7d2f\u79ef\u5206\u5e03\u51fd\u6570\uff08CDF\uff09\u7684\u51fd\u6570\uff0cNumPy\u5e93\u7528\u4e8e\u751f\u6210\u968f\u673a\u6570\u548c\u6570\u7ec4\u64cd\u4f5c\uff0cMatplotlib\u5e93\u7528\u4e8e\u6570\u636e\u7684\u53ef\u89c6\u5316\u3002\u901a\u8fc7\u7ed3\u5408\u4f7f\u7528\u8fd9\u4e9b\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u751f\u6210\u6b63\u6001\u5206\u5e03\u3001\u8ba1\u7b97\u76f8\u5173\u503c\u5e76\u8fdb\u884c\u53ef\u89c6\u5316\u5206\u6790\u3002\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u60a8\u80fd\u591f\u638c\u63e1\u5728Python\u4e2d\u6c42\u6b63\u6001\u5206\u5e03\u503c\u7684\u65b9\u6cd5\uff0c\u5e76\u5e94\u7528\u5230\u5b9e\u9645\u7684\u6570\u636e\u5206\u6790\u4e2d\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u968f\u673a\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u968f\u673a\u6570\u3002\u5177\u4f53\u65b9\u6cd5\u662f\u4f7f\u7528<code>numpy.random.normal()<\/code>\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5141\u8bb8\u4f60\u6307\u5b9a\u5747\u503c\u3001\u6807\u51c6\u5dee\u548c\u751f\u6210\u968f\u673a\u6570\u7684\u6570\u91cf\u3002\u4f8b\u5982\uff0c\u751f\u6210\u5747\u503c\u4e3a0\uff0c\u6807\u51c6\u5dee\u4e3a1\u7684100\u4e2a\u6b63\u6001\u5206\u5e03\u968f\u673a\u6570\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\nmean = 0\nstd_dev = 1\nnum_samples = 100\nrandom_numbers = np.random.normal(mean, std_dev, num_samples)\n<\/code><\/pre>\n<p><strong>Python\u4e2d\u5982\u4f55\u7ed8\u5236\u6b63\u6001\u5206\u5e03\u7684\u6982\u7387\u5bc6\u5ea6\u51fd\u6570\uff1f<\/strong><br \/>\u8981\u7ed8\u5236\u6b63\u6001\u5206\u5e03\u7684\u6982\u7387\u5bc6\u5ea6\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u548cSciPy\u5e93\u3002SciPy\u7684<code>scipy.stats.norm<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u65b9\u6cd5\u6765\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684\u6982\u7387\u5bc6\u5ea6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u7ed8\u5236\u6807\u51c6\u6b63\u6001\u5206\u5e03\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\nimport matplotlib.pyplot as plt\nimport scipy.stats as stats\n\nx = np.linspace(-4, 4, 100)\ny = stats.norm.pdf(x, 0, 1)  # \u5747\u503c\u4e3a0\uff0c\u6807\u51c6\u5dee\u4e3a1\nplt.plot(x, y)\nplt.title(&#39;Standard Normal Distribution&#39;)\nplt.xlabel(&#39;x&#39;)\nplt.ylabel(&#39;Probability Density&#39;)\nplt.grid()\nplt.show()\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u8ba1\u7b97\u6b63\u6001\u5206\u5e03\u7684\u7d2f\u79ef\u5206\u5e03\u51fd\u6570\uff08CDF\uff09\u503c\uff1f<\/strong><br \/>\u7d2f\u79ef\u5206\u5e03\u51fd\u6570\uff08CDF\uff09\u53ef\u4ee5\u4f7f\u7528SciPy\u5e93\u4e2d\u7684<code>scipy.stats.norm.cdf()<\/code>\u51fd\u6570\u6765\u8ba1\u7b97\u3002\u6b64\u51fd\u6570\u63a5\u53d7\u6570\u503c\u3001\u5747\u503c\u548c\u6807\u51c6\u5dee\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd4\u56de\u5c0f\u4e8e\u6216\u7b49\u4e8e\u8be5\u6570\u503c\u7684\u6982\u7387\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97\u5747\u503c\u4e3a0\uff0c\u6807\u51c6\u5dee\u4e3a1\u7684\u6b63\u6001\u5206\u5e03\u4e2d\uff0cx=1\u7684CDF\u503c\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">from scipy.stats import norm\n\nmean = 0\nstd_dev = 1\nx = 1\ncdf_value = norm.cdf(x, mean, std_dev)\nprint(f&#39;The CDF value at x={x} is {cdf_value}&#39;)\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u5728Python\u4e2d\u7075\u6d3b\u5730\u5904\u7406\u6b63\u6001\u5206\u5e03\u76f8\u5173\u7684\u8ba1\u7b97\u548c\u53ef\u89c6\u5316\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u6c42\u6b63\u6001\u5206\u5e03\u7684\u503c\u53ef\u4ee5\u4f7f\u7528SciPy\u5e93\u3001NumPy\u5e93\u3001Matplotlib\u5e93\u3002SciPy\u5e93\u63d0\u4f9b\u4e86 [&hellip;]","protected":false},"author":3,"featured_media":1053049,"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\/1053041"}],"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=1053041"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1053041\/revisions"}],"predecessor-version":[{"id":1053052,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1053041\/revisions\/1053052"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1053049"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1053041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1053041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1053041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}