{"id":969411,"date":"2024-12-27T05:16:40","date_gmt":"2024-12-26T21:16:40","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/969411.html"},"modified":"2024-12-27T05:16:42","modified_gmt":"2024-12-26T21:16:42","slug":"python%e5%a6%82%e4%bd%95%e6%8c%89%e6%a6%82%e7%8e%87%e6%8a%bd%e6%a0%b7","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/969411.html","title":{"rendered":"python\u5982\u4f55\u6309\u6982\u7387\u62bd\u6837"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24183714\/b2d9ab5e-cdba-4679-a802-06ac826115ca.webp\" alt=\"python\u5982\u4f55\u6309\u6982\u7387\u62bd\u6837\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u8fdb\u884c\u6309\u6982\u7387\u62bd\u6837\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5982\u4f7f\u7528numpy\u5e93\u7684<code>numpy.random.choice<\/code>\u51fd\u6570\u3001<code>random.choices<\/code>\u51fd\u6570\u3001\u4ee5\u53ca\u81ea\u5b9a\u4e49\u52a0\u6743\u62bd\u6837\u51fd\u6570\u7b49\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u5e76\u7ed9\u51fa\u793a\u4f8b\u3002<\/strong> \u4f7f\u7528<code>numpy.random.choice<\/code>\u51fd\u6570\u662f\u4e00\u79cd\u5e38\u89c1\u4e14\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u5b83\u5141\u8bb8\u76f4\u63a5\u6307\u5b9a\u6bcf\u4e2a\u5143\u7d20\u7684\u6982\u7387\uff0c\u9002\u5408\u4e8e\u9700\u8981\u8fdb\u884c\u5927\u91cf\u62bd\u6837\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001NUMPY\u5e93\u4e2d\u7684\u62bd\u6837\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>NumPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u5b66\u5e93\uff0c\u63d0\u4f9b\u4e86\u591a\u79cd\u968f\u673a\u51fd\u6570\uff0c\u5176\u4e2d<code>numpy.random.choice<\/code>\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u6839\u636e\u7ed9\u5b9a\u7684\u6982\u7387\u8fdb\u884c\u62bd\u6837\u3002<\/p>\n<\/p>\n<p><h4>1\u3001<code>numpy.random.choice<\/code>\u51fd\u6570\u7684\u4f7f\u7528<\/h4>\n<\/p>\n<p><p><code>numpy.random.choice<\/code>\u51fd\u6570\u5141\u8bb8\u4ece\u4e00\u4e2a\u6570\u7ec4\u4e2d\u968f\u673a\u9009\u62e9\u5143\u7d20\uff0c\u5e76\u4e14\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u5143\u7d20\u6307\u5b9a\u88ab\u9009\u62e9\u7684\u6982\u7387\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u5b9a\u4e49\u5143\u7d20\u548c\u5176\u5bf9\u5e94\u7684\u6982\u7387<\/strong><\/h2>\n<p>elements = [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;]<\/p>\n<p>probabilities = [0.1, 0.3, 0.4, 0.2]<\/p>\n<h2><strong>\u4ece\u5143\u7d20\u4e2d\u6309\u6982\u7387\u62bd\u6837<\/strong><\/h2>\n<p>sample = np.random.choice(elements, size=10, p=probabilities)<\/p>\n<p>print(sample)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c<code>numpy.random.choice<\/code>\u51fd\u6570\u4ece\u5143\u7d20<code>[&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;]<\/code>\u4e2d\u62bd\u53d610\u6b21\uff0c\u5e76\u4e14\u6bcf\u4e2a\u5143\u7d20\u88ab\u62bd\u53d6\u7684\u6982\u7387\u5206\u522b\u4e3a0.1, 0.3, 0.4, 0.2\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u6839\u636e\u6307\u5b9a\u6982\u7387\u8fdb\u884c\u62bd\u6837\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f18\u7f3a\u70b9\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>numpy.random.choice<\/code>\u8fdb\u884c\u6982\u7387\u62bd\u6837\u7684\u4f18\u70b9\u5728\u4e8e\u5176\u7b80\u5355\u6027\u548c\u9ad8\u6548\u6027\uff0c\u7279\u522b\u9002\u5408\u9700\u8981\u8fdb\u884c\u5927\u91cf\u62bd\u6837\u7684\u573a\u666f\u3002\u7136\u800c\uff0c\u5b83\u8981\u6c42\u6240\u6709\u6982\u7387\u4e4b\u548c\u5fc5\u987b\u7b49\u4e8e1\uff0c\u5426\u5219\u4f1a\u5f15\u53d1\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528RANDOM\u5e93\u8fdb\u884c\u6982\u7387\u62bd\u6837<\/p>\n<\/p>\n<p><p>Python\u7684\u6807\u51c6\u5e93<code>random<\/code>\u4e5f\u63d0\u4f9b\u4e86\u8fdb\u884c\u52a0\u6743\u62bd\u6837\u7684\u529f\u80fd\uff0c\u5373<code>random.choices<\/code>\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h4>1\u3001<code>random.choices<\/code>\u51fd\u6570\u7684\u4f7f\u7528<\/h4>\n<\/p>\n<p><p><code>random.choices<\/code>\u51fd\u6570\u53ef\u4ee5\u4ece\u4e00\u4e2a\u5e8f\u5217\u4e2d\u968f\u673a\u9009\u62e9\u5143\u7d20\uff0c\u5e76\u5141\u8bb8\u4e3a\u6bcf\u4e2a\u5143\u7d20\u6307\u5b9a\u6743\u91cd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<h2><strong>\u5b9a\u4e49\u5143\u7d20\u548c\u5176\u5bf9\u5e94\u7684\u6743\u91cd<\/strong><\/h2>\n<p>elements = [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;]<\/p>\n<p>weights = [1, 3, 4, 2]<\/p>\n<h2><strong>\u4ece\u5143\u7d20\u4e2d\u6309\u6743\u91cd\u62bd\u6837<\/strong><\/h2>\n<p>sample = random.choices(elements, weights=weights, k=10)<\/p>\n<p>print(sample)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>random.choices<\/code>\u4ece\u5143\u7d20\u4e2d\u8fdb\u884c10\u6b21\u62bd\u6837\uff0c\u6743\u91cd\u5206\u522b\u4e3a1, 3, 4, 2\u3002<code>random.choices<\/code>\u7684\u597d\u5904\u662f\u6743\u91cd\u4e0d\u9700\u8981\u5f52\u4e00\u5316\uff0c\u5373\u4e0d\u9700\u8981\u76f8\u52a0\u4e3a1\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f18\u7f3a\u70b9\u5206\u6790<\/h4>\n<\/p>\n<p><p><code>random.choices<\/code>\u7684\u4f18\u70b9\u5728\u4e8e\u5176\u7075\u6d3b\u6027\uff0c\u5141\u8bb8\u4f7f\u7528\u6743\u91cd\u800c\u975e\u7cbe\u786e\u6982\u7387\uff0c\u8fd9\u4f7f\u5f97\u8bbe\u7f6e\u66f4\u52a0\u76f4\u89c2\u3002\u7136\u800c\uff0c\u4e0e<code>numpy.random.choice<\/code>\u76f8\u6bd4\uff0c\u5b83\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\u53ef\u80fd\u6548\u7387\u7a0d\u4f4e\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u81ea\u5b9a\u4e49\u52a0\u6743\u62bd\u6837\u51fd\u6570<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u52a0\u6743\u62bd\u6837\u51fd\u6570\uff0c\u4ee5\u6ee1\u8db3\u7279\u5b9a\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b9e\u73b0\u81ea\u5b9a\u4e49\u52a0\u6743\u62bd\u6837\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u7d2f\u79ef\u6982\u7387\u7684\u65b9\u6cd5\u5b9e\u73b0\u81ea\u5b9a\u4e49\u7684\u52a0\u6743\u62bd\u6837\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>def weighted_sample(elements, probabilities, k=1):<\/p>\n<p>    # \u8ba1\u7b97\u7d2f\u79ef\u6982\u7387<\/p>\n<p>    cum_prob = [sum(probabilities[:i+1]) for i in range(len(probabilities))]<\/p>\n<p>    samples = []<\/p>\n<p>    for _ in range(k):<\/p>\n<p>        r = random.random()<\/p>\n<p>        for i, cp in enumerate(cum_prob):<\/p>\n<p>            if r &lt; cp:<\/p>\n<p>                samples.append(elements[i])<\/p>\n<p>                break<\/p>\n<p>    return samples<\/p>\n<p>elements = [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;]<\/p>\n<p>probabilities = [0.1, 0.3, 0.4, 0.2]<\/p>\n<h2><strong>\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\u8fdb\u884c\u62bd\u6837<\/strong><\/h2>\n<p>sample = weighted_sample(elements, probabilities, k=10)<\/p>\n<p>print(sample)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u5b9e\u73b0\u4e2d\uff0c\u9996\u5148\u8ba1\u7b97\u7d2f\u79ef\u6982\u7387\uff0c\u7136\u540e\u751f\u6210\u4e00\u4e2a\u968f\u673a\u6570\uff0c\u6839\u636e\u7d2f\u79ef\u6982\u7387\u9009\u62e9\u76f8\u5e94\u7684\u5143\u7d20\u3002\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u7075\u6d3b\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f18\u7f3a\u70b9\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u81ea\u5b9a\u4e49\u52a0\u6743\u62bd\u6837\u51fd\u6570\u7684\u4e3b\u8981\u4f18\u70b9\u662f\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u8fdb\u884c\u8c03\u6574\u3002\u7136\u800c\uff0c\u4e0e\u6807\u51c6\u5e93\u51fd\u6570\u76f8\u6bd4\uff0c\u5b83\u53ef\u80fd\u9700\u8981\u66f4\u591a\u7684\u8ba1\u7b97\u8d44\u6e90\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4e0d\u540c\u65b9\u6cd5\u7684\u6bd4\u8f83\u548c\u9009\u62e9<\/p>\n<\/p>\n<p><p>\u5728\u9009\u62e9\u9002\u5408\u7684\u6982\u7387\u62bd\u6837\u65b9\u6cd5\u65f6\uff0c\u9700\u8981\u8003\u8651\u6570\u636e\u89c4\u6a21\u3001\u6027\u80fd\u8981\u6c42\u4ee5\u53ca\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u6027\u80fd\u5bf9\u6bd4<\/h4>\n<\/p>\n<ul>\n<li><strong>NumPy\u7684<code>numpy.random.choice<\/code><\/strong>\uff1a\u6700\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\uff0c\u6027\u80fd\u4f18\u5f02\uff0c\u4e14\u4ee3\u7801\u7b80\u6d01\u3002<\/li>\n<li><strong><code>random.choices<\/code><\/strong>\uff1a\u9002\u5408\u4e2d\u7b49\u89c4\u6a21\u6570\u636e\uff0c\u4ee3\u7801\u7b80\u5355\uff0c\u9002\u7528\u4e8e\u9700\u8981\u4f7f\u7528\u6743\u91cd\u7684\u573a\u666f\u3002<\/li>\n<li><strong>\u81ea\u5b9a\u4e49\u51fd\u6570<\/strong>\uff1a\u9002\u5408\u5c0f\u89c4\u6a21\u6570\u636e\u6216\u5bf9\u7075\u6d3b\u6027\u6709\u7279\u6b8a\u8981\u6c42\u7684\u573a\u666f\u3002<\/li>\n<\/ul>\n<p><h4>2\u3001\u4f7f\u7528\u573a\u666f<\/h4>\n<\/p>\n<ul>\n<li><strong>\u5927\u6570\u636e\u5904\u7406<\/strong>\uff1a\u63a8\u8350\u4f7f\u7528<code>numpy.random.choice<\/code>\uff0c\u5176\u6027\u80fd\u548c\u7b80\u6d01\u6027\u662f\u4e3b\u8981\u4f18\u52bf\u3002<\/li>\n<li><strong>\u7b80\u5355\u6743\u91cd\u62bd\u6837<\/strong>\uff1a<code>random.choices<\/code>\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u9009\u62e9\uff0c\u7279\u522b\u662f\u5f53\u6570\u636e\u89c4\u6a21\u4e0d\u5927\u65f6\u3002<\/li>\n<li><strong>\u9700\u8981\u81ea\u5b9a\u4e49\u903b\u8f91<\/strong>\uff1a\u81ea\u5b9a\u4e49\u52a0\u6743\u62bd\u6837\u51fd\u6570\u53ef\u63d0\u4f9b\u6700\u5927\u7075\u6d3b\u6027\uff0c\u9002\u7528\u4e8e\u7279\u5b9a\u9700\u6c42\u3002<\/li>\n<\/ul>\n<p><p>\u4e94\u3001\u603b\u7ed3\u548c\u5efa\u8bae<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u8fdb\u884c\u6309\u6982\u7387\u62bd\u6837\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4f9b\u9009\u62e9\uff0c\u9009\u62e9\u9002\u5408\u7684\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u60a8\u66f4\u9ad8\u6548\u5730\u5b8c\u6210\u4efb\u52a1\u3002\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0c\u4f18\u5148\u8003\u8651\u4f7f\u7528NumPy\u5e93\u7684<code>numpy.random.choice<\/code>\u51fd\u6570\uff0c\u5b83\u63d0\u4f9b\u4e86\u6700\u4f18\u7684\u6027\u80fd\u548c\u7b80\u6d01\u7684\u4ee3\u7801\u3002\u5728\u9700\u8981\u66f4\u7075\u6d3b\u7684\u52a0\u6743\u62bd\u6837\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>random.choices<\/code>\u6216\u81ea\u5b9a\u4e49\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u786e\u4fdd\u5728\u4f7f\u7528\u524d\u5bf9\u6982\u7387\u6216\u6743\u91cd\u8fdb\u884c\u5408\u7406\u7684\u8bbe\u7f6e\u548c\u9a8c\u8bc1\uff0c\u4ee5\u786e\u4fdd\u62bd\u6837\u7ed3\u679c\u7684\u51c6\u786e\u6027\u548c\u53ef\u9760\u6027\u3002\u8fd9\u5c06\u6709\u52a9\u4e8e\u63d0\u9ad8\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u7684\u8d28\u91cf\uff0c\u6ee1\u8db3\u4e0d\u540c\u5e94\u7528\u573a\u666f\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u6309\u6982\u7387\u62bd\u6837\u7684\u529f\u80fd\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u7684<code>numpy.random.choice()<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\u6309\u6982\u7387\u62bd\u6837\u3002\u8be5\u51fd\u6570\u5141\u8bb8\u7528\u6237\u6307\u5b9a\u6bcf\u4e2a\u5143\u7d20\u88ab\u9009\u62e9\u7684\u6982\u7387\uff0c\u4ece\u800c\u5b9e\u73b0\u975e\u5747\u5300\u7684\u62bd\u6837\u3002\u7528\u6237\u9700\u8981\u63d0\u4f9b\u4e00\u4e2a\u6570\u7ec4\u4f5c\u4e3a\u6837\u672c\uff0c\u4ee5\u53ca\u4e00\u4e2a\u4e0e\u6837\u672c\u5927\u5c0f\u76f8\u540c\u7684\u6982\u7387\u6570\u7ec4\uff0c\u786e\u4fdd\u6982\u7387\u4e4b\u548c\u4e3a1\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\nsamples = [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;]\nprobabilities = [0.1, 0.2, 0.3, 0.4]\nchosen_sample = np.random.choice(samples, p=probabilities)\n<\/code><\/pre>\n<p><strong>\u5728Python\u4e2d\u6309\u6982\u7387\u62bd\u6837\u65f6\u5982\u4f55\u5904\u7406\u91cd\u590d\u6837\u672c\uff1f<\/strong><br \/>\u5982\u679c\u5e0c\u671b\u5728\u62bd\u6837\u8fc7\u7a0b\u4e2d\u5141\u8bb8\u91cd\u590d\u6837\u672c\uff0c\u53ef\u4ee5\u5728<code>numpy.random.choice()<\/code>\u4e2d\u8bbe\u7f6e<code>replace=True<\/code>\u3002\u8fd9\u610f\u5473\u7740\u6bcf\u6b21\u62bd\u6837\u540e\uff0c\u6837\u672c\u5c06\u88ab\u653e\u56de\uff0c\u4ece\u800c\u53ef\u80fd\u5728\u540e\u7eed\u62bd\u6837\u4e2d\u518d\u6b21\u88ab\u9009\u62e9\u3002\u76f8\u53cd\uff0c\u5982\u679c\u5e0c\u671b\u4e0d\u91cd\u590d\u62bd\u6837\uff0c\u53ef\u4ee5\u5c06<code>replace<\/code>\u53c2\u6570\u8bbe\u7f6e\u4e3a<code>False<\/code>\u3002\u8fd9\u4e3a\u7528\u6237\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u62bd\u6837\u9009\u62e9\u3002<\/p>\n<p><strong>\u4f7f\u7528Pandas\u5e93\u8fdb\u884c\u6309\u6982\u7387\u62bd\u6837\u7684\u6700\u4f73\u5b9e\u8df5\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>Pandas\u5e93\u540c\u6837\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u62bd\u6837\u65b9\u6cd5\u3002\u53ef\u4ee5\u5229\u7528<code>DataFrame.sample()<\/code>\u51fd\u6570\u7684<code>weights<\/code>\u53c2\u6570\u6765\u6309\u6982\u7387\u62bd\u6837\u3002\u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u4f20\u5165\u4e00\u4e2a\u5305\u542b\u6743\u91cd\u7684\u5217\uff0c\u5e76\u8bbe\u7f6e<code>replace<\/code>\u53c2\u6570\u6765\u63a7\u5236\u662f\u5426\u5141\u8bb8\u91cd\u590d\u62bd\u6837\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Pandas\u8fdb\u884c\u6309\u6982\u7387\u62bd\u6837\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndata = {&#39;item&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;], &#39;weights&#39;: [0.1, 0.2, 0.3, 0.4]}\ndf = pd.DataFrame(data)\nsampled_df = df.sample(n=2, weights=&#39;weights&#39;, replace=True)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u5728\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u65f6\u5c24\u4e3a\u6709\u6548\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u5feb\u901f\u83b7\u53d6\u7b26\u5408\u9700\u6c42\u7684\u6837\u672c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8fdb\u884c\u6309\u6982\u7387\u62bd\u6837\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5982\u4f7f\u7528numpy\u5e93\u7684numpy.random.choice [&hellip;]","protected":false},"author":3,"featured_media":969417,"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\/969411"}],"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=969411"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/969411\/revisions"}],"predecessor-version":[{"id":969421,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/969411\/revisions\/969421"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/969417"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=969411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=969411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=969411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}