{"id":70651,"date":"2024-01-31T16:14:18","date_gmt":"2024-01-31T08:14:18","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=70651"},"modified":"2024-01-31T16:14:19","modified_gmt":"2024-01-31T08:14:19","slug":"python%e4%b8%adscipy-special-sph_harm%e5%87%bd%e6%95%b0%e8%be%93%e5%87%ba%e4%b8%banannanj%e6%80%8e%e4%b9%88%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/70651.html","title":{"rendered":"python\u4e2dscipy.special.sph_harm\u51fd\u6570\u8f93\u51fa\u4e3a(nan+nanj)\u600e\u4e48\u89e3\u51b3"},"content":{"rendered":"<p>\u5728<strong>Python<\/strong>\u4e2d\u4f7f\u7528<strong>scipy.special.sph_harm<\/strong>\u51fd\u6570\u65f6\u51fa\u73b0<strong>(nan+nanj)<\/strong>\u7684\u95ee\u9898\u901a\u5e38\u662f\u7531\u4e8e\u8f93\u5165\u53c2\u6570\u51fa\u73b0\u4e86\u4e0d\u5408\u7406\u7684\u503c\uff0c\u9020\u6210\u4e86\u51fd\u6570\u65e0\u6cd5\u8ba1\u7b97\u51fa\u6b63\u786e\u7684\u7ed3\u679c\u3002\u8fd9\u4e2a\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u9636\u6570m\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u6b21\u6570l\uff0c\u5b83\u4eec\u9700\u8981\u6ee1\u8db3|m| <= l\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u662f\u65b9\u4f4d\u89d2phi\uff0c\u7b2c\u56db\u4e2a\u53c2\u6570\u662f\u6781\u89d2theta\u3002\u8981\u4fee\u590d<strong>(nan+nanj)<\/strong>\u8fd9\u4e00\u95ee\u9898\uff0c\u53ef\u4ee5<strong>\u5206\u6b65\u68c0\u67e5\u53c2\u6570\u5408\u6cd5\u6027<\/strong>\u3001<strong>\u907f\u514d\u6ea2\u51fa<\/strong>\u3001<strong>\u4fdd\u8bc1\u8f93\u5165\u4e3a\u5b9e\u6570<\/strong>\u3001<strong>\u9488\u5bf9\u7279\u6b8a\u503c<\/strong>\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u8be6\u7ec6\u63a2\u8ba8\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u6240\u9700\u7684\u4e0d\u540c\u65b9\u9762\u3002<\/p>\n<h2><strong>\u4e00\u3001\u53c2\u6570\u68c0\u67e5\u548c\u9a8c\u8bc1<\/strong><\/h2>\n<p>\u786e\u4fdd\u4f20\u9012\u7ed9<strong>sph_harm<\/strong>\u7684\u53c2\u6570m\u548cl\u662f\u6574\u6570\uff0c\u4e14\u5b83\u4eec\u9075\u4ece\u5173\u7cfb|m| <= l\u3002\u5982\u679c\u53c2\u6570\u8d85\u51fa\u8fd9\u4e2a\u9650\u5236\uff0c<strong>sph_harm<\/strong>\u5c06\u65e0\u6cd5\u6b63\u786e\u8ba1\u7b97\uff0c\u53ef\u80fd\u8fd4\u56de\u975e\u6570\u5b57<strong>(nan)<\/strong>\u503c\u3002\u6b64\u5916\uff0ctheta\u5e94\u5728[0, \u03c0]\u8303\u56f4\u5185\uff0cphi\u5e94\u5728[0, 2\u03c0]\u8303\u56f4\u5185\u3002\u504f\u79bb\u4e86\u8fd9\u4e9b\u8303\u56f4\u7684\u503c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u9519\u8bef\u7684\u8f93\u51fa\u3002<\/p>\n<h2><strong>\u4e8c\u3001\u6570\u636e\u7c7b\u578b\u548c\u8303\u56f4<\/strong><\/h2>\n<p>\u786e\u4fddtheta\u548cphi\u662f\u6d6e\u70b9\u6570\uff0c\u8fd9\u5bf9\u4e8e<strong>sph_harm<\/strong>\u51fd\u6570\u6b63\u5e38\u5de5\u4f5c\u662f\u5fc5\u8981\u7684\u3002\u5982\u679c\u8fd9\u4e9b\u53c2\u6570\u7684\u8303\u56f4\u8fc7\u5927\uff0c\u5b83\u4eec\u53ef\u80fd\u5bfc\u81f4\u6d6e\u70b9\u6570\u6ea2\u51fa\uff0c\u4ece\u800c\u8fd4\u56de<strong>(nan+nanj)<\/strong>\u3002\u5728\u8f93\u5165\u8fd9\u4e9b\u53c2\u6570\u4e4b\u524d\uff0c\u53ef\u5c1d\u8bd5\u5bf9\u5176\u8fdb\u884c\u6807\u51c6\u5316\u6216\u5f52\u4e00\u5316\u3002<\/p>\n<h2><strong>\u4e09\u3001\u7279\u522b\u6ce8\u610f\u7684\u6570\u503c\u95ee\u9898<\/strong><\/h2>\n<p>\u8fd8\u5e94\u8be5\u6ce8\u610f\u6570\u503c\u7a33\u5b9a\u6027\u7684\u95ee\u9898\u3002\u7279\u522b\u5f53\u9636\u6570m\u548c\u6b21\u6570l\u975e\u5e38\u5927\u65f6\uff0c\u4e14theta\u63a5\u8fd10\u6216\u03c0\uff0c\u8ba1\u7b97\u8fc7\u7a0b\u53ef\u80fd\u4f1a\u53d8\u5f97\u4e0d\u7a33\u5b9a\u3002\u8981\u5904\u7406\u6b64\u7c7b\u95ee\u9898\uff0c\u53ef\u4ee5\u901a\u8fc7\u9009\u62e9\u66f4\u52a0\u7a33\u5b9a\u7684\u7b97\u6cd5\uff0c\u6216\u8005\u4f7f\u7528\u6570\u503c\u6b63\u5219\u5316\u6280\u672f\u6765\u907f\u514d\u3002<\/p>\n<h2><strong>\u56db\u3001\u8c03\u8bd5\u548c\u9519\u8bef\u5904\u7406<\/strong><\/h2>\n<p>\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u5f02\u5e38\u5904\u7406\uff0c\u5f53\u4f7f\u7528<strong>sph_harm<\/strong>\u51fd\u6570\u65f6\u6355\u6349\u53ef\u80fd\u53d1\u751f\u7684\u5f02\u5e38\uff0c\u5e76\u636e\u6b64\u8c03\u6574\u53c2\u6570\u3002\u6b64\u5916\uff0c\u8f93\u51fa\u4e2d\u95f4\u7684\u8ba1\u7b97\u7ed3\u679c\uff0c\u4ee5\u5e2e\u52a9\u8bc6\u522b\u95ee\u9898\u6240\u5728\u3002<\/p>\n<p>\u4e0b\u9762\u63d0\u4f9b\u4e00\u4e2a\u7b80\u6d01\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u6f14\u793a\u5982\u4f55\u5728\u8c03\u7528<strong>sph_harm<\/strong>\u51fd\u6570\u524d\u68c0\u67e5\u5e76\u4fee\u590d\u4efb\u4f55\u53ef\u80fd\u5bfc\u81f4\u95ee\u9898\u7684\u53c2\u6570\uff1a<\/p>\n<p>&#8220;`python<\/p>\n<p>from scipy.special import sph_harm<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u5b9a\u4e49\u4f60\u7684\u53c2\u6570<\/strong><\/h2>\n<p>m = 1<\/p>\n<p>l = 1<\/p>\n<p>theta = np.pi \/ 4<\/p>\n<p>phi = np.pi \/ 2<\/p>\n<h2><strong>\u53c2\u6570\u9a8c\u8bc1\u4e0e\u4fee\u590d<\/strong><\/h2>\n<p>if not (np.isscalar(m) and np.isscalar(l) and np.isscalar(theta) and np.isscalar(phi)):<\/p>\n<p>    r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se ValueError(&#8220;\u53c2\u6570\u5fc5\u987b\u662f\u6807\u91cf&#8221;)<\/p>\n<p>if not (-l <= m <= l):<\/p>\n<p>    raise ValueError(&#8220;\u5fc5\u987b\u6ee1\u8db3 -l <= m <= l\")<\/p>\n<p>if not (0 <= theta <= np.pi and 0 <= phi <= 2 * np.pi):<\/p>\n<p>    raise ValueError(&#8220;theta \u5fc5\u987b\u5728 [0, \u03c0] \u8303\u56f4\uff0cphi \u5fc5\u987b\u5728 [0, 2\u03c0] \u8303\u56f4\u5185&#8221;)<\/p>\n<h2><strong>\u8ba1\u7b97\u7403\u8c10\u51fd\u6570<\/strong><\/h2>\n<p>try:<\/p>\n<p>    result = sph_harm(m, l, phi, theta)<\/p>\n<p>    print(result)<\/p>\n<p>except Exception as e:<\/p>\n<p>    print(f&#8221;\u8ba1\u7b97\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u9519\u8bef: {e}&#8221;)<\/p>\n<p>&#8220;`<\/p>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u672c\u6587\u5047\u5b9a\u8bfb\u8005\u5df2\u7ecf\u719f\u6089\u4e86<strong>sph_harm<\/strong>\u51fd\u6570\u7684\u4f7f\u7528\uff0c\u5e76\u638c\u63e1\u4e86\u4e00\u5b9a\u7684Python\u7f16\u7a0b\u6280\u80fd\u3002\u8c03\u8bd5\u548c\u4fee\u590d<strong>(nan+nanj)<\/strong>\u95ee\u9898\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u6570\u5b66\u548c\u7f16\u7a0b\u65b9\u9762\u7684\u57fa\u7840\u77e5\u8bc6\u3002\u5728\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u65f6\uff0c\u5e94\u7ed3\u5408\u5177\u4f53\u60c5\u51b5\u91c7\u53d6\u9002\u5f53\u7684\u7b56\u7565\u3002<\/p>\n<p> <strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><strong>\u4e3a\u4ec0\u4e48\u4f7f\u7528python\u4e2dscipy.special.sph_harm\u51fd\u6570\u65f6\u4f1a\u8f93\u51fa\u4e3a(nan+nanj)\uff1f<\/strong><\/p>\n<p>\u8fd9\u79cd\u8f93\u51fa\u901a\u5e38\u662f\u7531\u4e8e\u8f93\u5165\u6570\u636e\u8d85\u51fa\u4e86\u51fd\u6570\u7684\u6709\u6548\u8303\u56f4\u3002sph_harm\u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u7403\u8c10\u51fd\u6570\uff0c\u5b83\u7684\u8f93\u5165\u53c2\u6570\u662f\u6574\u6570\u9636\u6570\u548c\u78c1\u91cf\u5b50\u6570\uff0c\u5982\u679c\u8fd9\u4e9b\u53c2\u6570\u8d85\u51fa\u4e86\u5141\u8bb8\u7684\u8303\u56f4\uff0c\u5c31\u4f1a\u5bfc\u81f4\u8f93\u51fa\u4e3anan\uff08\u975e\u6570\u5b57\uff09\u3002<\/p>\n<p><strong>\u5982\u4f55\u89e3\u51b3python\u4e2dscipy.special.sph_harm\u51fd\u6570\u8f93\u51fa\u4e3a(nan+nanj)\u7684\u95ee\u9898\uff1f<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9996\u5148\u8981\u68c0\u67e5\u8f93\u5165\u53c2\u6570\u7684\u53d6\u503c\u8303\u56f4\u662f\u5426\u6b63\u786e\u3002\u786e\u4fdd\u6574\u6570\u53c2\u6570\u5904\u4e8e\u5141\u8bb8\u7684\u8303\u56f4\u5185\u3002\u5982\u679c\u8f93\u5165\u53c2\u6570\u6b63\u786e\uff0c\u4f46\u4ecd\u7136\u51fa\u73b0\u8fd9\u79cd\u8f93\u51fa\uff0c\u53ef\u80fd\u662f\u51fd\u6570\u5b9e\u73b0\u4e0a\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u66f4\u65b0\u4f7f\u7528\u7684Python\u548cSciPy\u7248\u672c\uff0c\u4ee5\u83b7\u53d6\u4fee\u590d\u6216\u6539\u8fdb\u3002<\/p>\n<p><strong>\u9664\u4e86\u8f93\u5165\u53c2\u6570\u8d85\u51fa\u8303\u56f4\uff0c\u8fd8\u6709\u54ea\u4e9b\u53ef\u80fd\u5bfc\u81f4python\u4e2dscipy.special.sph_harm\u51fd\u6570\u8f93\u51fa\u4e3a(nan+nanj)\u7684\u539f\u56e0\uff1f<\/strong><\/p>\n<p>\u9664\u4e86\u53c2\u6570\u8d85\u51fa\u8303\u56f4\u5916\uff0c\u53ef\u80fd\u7684\u539f\u56e0\u8fd8\u5305\u62ec\u51fd\u6570\u8ba1\u7b97\u65f6\u7684\u6570\u503c\u4e0d\u7a33\u5b9a\u6027\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u66f4\u9ad8\u7cbe\u5ea6\u7684\u6570\u636e\u7c7b\u578b\uff08\u5982\u590d\u6570\u7c7b\u578b\uff09\u6216\u8005\u5c1d\u8bd5\u907f\u514d\u8f93\u5165\u6570\u503c\u8fc7\u5927\u6216\u8fc7\u5c0f\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u5176\u4ed6\u8f6f\u4ef6\u5305\u7684\u7403\u8c10\u51fd\u6570\u5b9e\u73b0\u6765\u68c0\u67e5\u7ed3\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u4f7f\u7528scipy.special.sph_harm\u51fd\u6570\u65f6\u51fa\u73b0(nan+nanj)\u7684\u95ee\u9898\u901a\u5e38\u662f\u7531\u4e8e [&hellip;]","protected":false},"author":1,"featured_media":70653,"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\/70651"}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=70651"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/70651\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/70653"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=70651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=70651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=70651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}