{"id":205029,"date":"2025-05-29T15:56:39","date_gmt":"2025-05-29T07:56:39","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205029\/"},"modified":"2025-05-29T15:56:39","modified_gmt":"2025-05-29T07:56:39","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-python-%e5%9c%a8%e6%8c%87%e5%ae%9a%e7%a9%ba%e9%97%b4%e5%86%85%e7%94%9f%e6%88%90%e9%9a%8f%e6%9c%ba%e4%b8%89%e7%bb%b4%e5%9d%90%e6%a0%87%e7%82%b9%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205029\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Python \u5728\u6307\u5b9a\u7a7a\u95f4\u5185\u751f\u6210\u968f\u673a\u4e09\u7ef4\u5750\u6807\u70b9\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 Python \u5728\u6307\u5b9a\u7a7a\u95f4\u5185\u751f\u6210\u968f\u673a\u4e09\u7ef4\u5750\u6807\u70b9\uff1f<\/h1>\n<p>\u6587\u7ae0\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300a\u5982\u4f55\u4f7f\u7528 Python \u5728\u6307\u5b9a\u7a7a\u95f4\u5185\u751f\u6210\u968f\u673a\u4e09\u7ef4\u5750\u6807\u70b9\uff1f\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241121\/1732200346673f479aebc63.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u6307\u5b9a\u7a7a\u95f4\u5185\u751f\u6210\u968f\u673a\u5750\u6807\u70b9\u4f4d\uff08\u4e09\u7ef4\uff09<\/strong><\/p>\n<p>\u5728\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u548c\u6a21\u62df\u4e2d\uff0c\u9700\u8981\u7ecf\u5e38\u751f\u6210\u5206\u5e03\u5728\u6307\u5b9a\u7a7a\u95f4\u5185\u7684\u968f\u673a\u5750\u6807\u70b9\u3002\u5728\u4e09\u7ef4\u7a7a\u95f4\u4e2d\uff0c\u8fd9\u610f\u5473\u7740\u751f\u6210\u5177\u6709 x\u3001y \u548c z \u5750\u6807\u7684\u70b9\u3002<\/p>\n<p>\u4e00\u4e2a\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u5747\u5300\u5206\u5e03\u3002\u8fd9\u53ef\u4ee5\u5229\u7528 numpy \u4e2d\u7684 random.uniform() \u51fd\u6570\u6765\u5b9e\u73b0\uff0c\u5b83\u5141\u8bb8\u6307\u5b9a\u6bcf\u4e2a\u5750\u6807\u7684\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u3002<\/p>\n<pre>import numpy as np\n\n# \u6307\u5b9a\u7a7a\u95f4\u8fb9\u754c\nmin_x, max_x = -10, 10\nmin_y, max_y = -10, 10\nmin_z, max_z = -10, 10\n\n# \u751f\u6210\u968f\u673a\u5750\u6807\u70b9\nnum_points = 1000\npoints = np.random.uniform(min_x, max_x, size=(num_points, 3))\npoints[:, 1] = np.random.uniform(min_y, max_y, size=num_points)\npoints[:, 2] = np.random.uniform(min_z, max_z, size=num_points)<\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5728\u7ed9\u5b9a\u7684\u7a7a\u95f4\u8303\u56f4\u5185\u751f\u6210\u5747\u5300\u5206\u5e03\u7684\u70b9\u3002\u8fd9\u4e9b\u70b9\u53ef\u4ee5\u7528\u4e8e\u5404\u79cd\u5e94\u7528\uff0c\u4f8b\u5982\u521b\u5efa 3d \u7c92\u5b50\u7cfb\u7edf\u6216\u6a21\u62df\u5176\u4ed6\u7269\u7406\u73b0\u8c61\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6b64\u65b9\u6cd5\u751f\u6210\u7684\u662f\u4e00\u4e2a\u5706\u67f1\u4f53\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u7403\u4f53\uff0c\u56e0\u4e3a z \u5750\u6807\u4e0d\u53d7 x \u548c y \u5750\u6807\u7684\u9650\u5236\u3002\u8981\u751f\u6210\u7403\u4f53\u4e2d\u7684\u70b9\uff0c\u53ef\u4ee5\u4f7f\u7528\u66f4\u590d\u6742\u7684\u65b9\u6cd5\uff0c\u4f8b\u5982 rejection sampling\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 Python \u5728\u6307\u5b9a\u7a7a\u95f4\u5185\u751f\u6210\u968f\u673a\u4e09\u7ef4\u5750\u6807\u70b9\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 Python \u5728\u6307\u5b9a\u7a7a&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205029","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205029","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205029"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205029\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}