{"id":985504,"date":"2024-12-27T07:37:13","date_gmt":"2024-12-26T23:37:13","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/985504.html"},"modified":"2024-12-27T07:37:15","modified_gmt":"2024-12-26T23:37:15","slug":"sinx%e5%a6%82%e4%bd%95%e7%94%a8python%e8%be%93%e5%87%ba","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/985504.html","title":{"rendered":"sinx\u5982\u4f55\u7528python\u8f93\u51fa"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24212631\/6f80b90b-760b-44f4-a190-d17253301b77.webp\" alt=\"sinx\u5982\u4f55\u7528python\u8f93\u51fa\" \/><\/p>\n<p><p> <strong>\u8981\u5728Python\u4e2d\u8f93\u51fasin(x)\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>math<\/code>\u5e93\u6216<code>numpy<\/code>\u5e93\u3002<\/strong> <code>math<\/code>\u5e93\u9002\u7528\u4e8e\u6807\u91cf\u8fd0\u7b97\uff0c\u800c<code>numpy<\/code>\u5e93\u5219\u9002\u7528\u4e8e\u6570\u7ec4\u8fd0\u7b97\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e24\u4e2a\u5e93\u6765\u8ba1\u7b97\u548c\u8f93\u51fasin(x)\u7684\u503c\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528MATH\u5e93\u8ba1\u7b97SIN(X)<\/h2>\n<\/p>\n<p><p><code>math<\/code>\u5e93\u662fPython\u7684\u6807\u51c6\u6570\u5b66\u5e93\uff0c\u9002\u5408\u7528\u4e8e\u7b80\u5355\u7684\u6570\u5b66\u8fd0\u7b97\u3002\u8981\u8ba1\u7b97\u6b63\u5f26\u503c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>math.sin()<\/code>\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u4ee5\u5f27\u5ea6\u4e3a\u5355\u4f4d\u8fdb\u884c\u8ba1\u7b97\uff0c\u56e0\u6b64\u5982\u679c\u4f60\u7684\u89d2\u5ea6\u662f\u4ee5\u5ea6\u4e3a\u5355\u4f4d\u7684\uff0c\u9700\u8981\u5148\u5c06\u5176\u8f6c\u6362\u4e3a\u5f27\u5ea6\u3002<\/p>\n<\/p>\n<p><h3>\u793a\u4f8b\u4ee3\u7801<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u5c06\u89d2\u5ea6\u4ece\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6<\/strong><\/h2>\n<p>degrees = 30<\/p>\n<p>radians = math.radians(degrees)<\/p>\n<h2><strong>\u8ba1\u7b97sin(x)<\/strong><\/h2>\n<p>sin_value = math.sin(radians)<\/p>\n<h2><strong>\u8f93\u51fa\u7ed3\u679c<\/strong><\/h2>\n<p>print(f&quot;sin({degrees}) = {sin_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u8be6\u7ec6\u89e3\u91ca<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u89d2\u5ea6\u8f6c\u6362<\/strong>\uff1a\u6570\u5b66\u4e2d\uff0c\u6b63\u5f26\u51fd\u6570\u4ee5\u5f27\u5ea6\u4e3a\u5355\u4f4d\u6765\u8ba1\u7b97\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4f60\u7684\u89d2\u5ea6\u662f30\u5ea6\uff0c\u5c31\u9700\u8981\u4f7f\u7528<code>math.radians()<\/code>\u51fd\u6570\u5c06\u5176\u8f6c\u6362\u4e3a\u5f27\u5ea6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8ba1\u7b97\u6b63\u5f26\u503c<\/strong>\uff1a\u4f7f\u7528<code>math.sin()<\/code>\u51fd\u6570\u6765\u8ba1\u7b97\u5f27\u5ea6\u503c\u7684\u6b63\u5f26\u503c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8f93\u51fa\u7ed3\u679c<\/strong>\uff1a\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u6765\u8f93\u51fa\u7ed3\u679c\uff0c\u66f4\u52a0\u6e05\u6670\u6613\u8bfb\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h2>\u4e8c\u3001\u4f7f\u7528NUMPY\u5e93\u8ba1\u7b97SIN(X)<\/h2>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u9700\u8981\u5bf9\u5927\u91cf\u6570\u636e\u8fdb\u884c\u6b63\u5f26\u8fd0\u7b97\uff0c\u6216\u8005\u9700\u8981\u5728\u6570\u7ec4\u4e0a\u8fdb\u884c\u64cd\u4f5c\uff0c<code>numpy<\/code>\u5e93\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\u3002<code>numpy<\/code>\u7684<code>sin()<\/code>\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u5bf9\u6570\u7ec4\u8fdb\u884c\u64cd\u4f5c\uff0c\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u7684\u6b63\u5f26\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u793a\u4f8b\u4ee3\u7801<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u89d2\u5ea6\u6570\u7ec4\uff08\u4ee5\u5ea6\u4e3a\u5355\u4f4d\uff09<\/strong><\/h2>\n<p>degrees_array = np.array([0, 30, 45, 60, 90])<\/p>\n<h2><strong>\u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6<\/strong><\/h2>\n<p>radians_array = np.radians(degrees_array)<\/p>\n<h2><strong>\u8ba1\u7b97sin(x)\u7684\u503c<\/strong><\/h2>\n<p>sin_values = np.sin(radians_array)<\/p>\n<h2><strong>\u8f93\u51fa\u7ed3\u679c<\/strong><\/h2>\n<p>for degree, sin_value in zip(degrees_array, sin_values):<\/p>\n<p>    print(f&quot;sin({degree}) = {sin_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u8be6\u7ec6\u89e3\u91ca<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u6570\u7ec4<\/strong>\uff1a\u4f7f\u7528<code>numpy.array()<\/code>\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u89d2\u5ea6\u7684\u6570\u7ec4\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u7ec4\u8f6c\u6362<\/strong>\uff1a\u4f7f\u7528<code>numpy.radians()<\/code>\u5c06\u89d2\u5ea6\u6570\u7ec4\u8f6c\u6362\u4e3a\u5f27\u5ea6\u6570\u7ec4\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6279\u91cf\u8ba1\u7b97<\/strong>\uff1a<code>numpy.sin()<\/code>\u53ef\u4ee5\u76f4\u63a5\u5bf9\u6574\u4e2a\u6570\u7ec4\u8fdb\u884c\u64cd\u4f5c\uff0c\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6240\u6709\u6b63\u5f26\u503c\u7684\u65b0\u6570\u7ec4\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8f93\u51fa\u7ed3\u679c<\/strong>\uff1a\u4f7f\u7528<code>zip()<\/code>\u51fd\u6570\u5c06\u89d2\u5ea6\u548c\u6b63\u5f26\u503c\u914d\u5bf9\uff0c\u5e76\u9010\u4e2a\u8f93\u51fa\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h2>\u4e09\u3001\u9009\u62e9\u5408\u9002\u7684\u5e93<\/h2>\n<\/p>\n<p><p>\u5bf9\u4e8e\u5c0f\u89c4\u6a21\u7684\u8ba1\u7b97\u6216\u7b80\u5355\u7684\u6570\u5b66\u64cd\u4f5c\uff0c<code>math<\/code>\u5e93\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u9009\u62e9\uff0c\u56e0\u4e3a\u5b83\u7b80\u5355\u6613\u7528\uff0c\u4e14\u662fPython\u7684\u6807\u51c6\u5e93\uff0c\u65e0\u9700\u989d\u5916\u5b89\u88c5\u3002\u800c\u5bf9\u4e8e\u9700\u8981\u5904\u7406\u5927\u91cf\u6570\u636e\u6216\u8fdb\u884c\u590d\u6742\u6570\u503c\u8ba1\u7b97\u7684\u60c5\u51b5\uff0c<code>numpy<\/code>\u5e93\u66f4\u4e3a\u5408\u9002\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u66f4\u9ad8\u6548\u7684\u6570\u7ec4\u8fd0\u7b97\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/h2>\n<\/p>\n<p><h3>\u8f93\u5165\u89d2\u5ea6\u5355\u4f4d\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u8bb8\u591a\u521d\u5b66\u8005\u53ef\u80fd\u4f1a\u5c06\u5ea6\u6570\u76f4\u63a5\u8f93\u5165\u5230<code>math.sin()<\/code>\u6216<code>numpy.sin()<\/code>\u4e2d\uff0c\u5bfc\u81f4\u8ba1\u7b97\u7ed3\u679c\u4e0d\u6b63\u786e\u3002<strong>\u4e00\u5b9a\u8981\u786e\u4fdd\u8f93\u5165\u7684\u89d2\u5ea6\u662f\u4ee5\u5f27\u5ea6\u4e3a\u5355\u4f4d\u7684<\/strong>\uff0c\u53ef\u4ee5\u4f7f\u7528<code>math.radians()<\/code>\u6216<code>numpy.radians()<\/code>\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><h3>\u6570\u503c\u7cbe\u5ea6\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u67d0\u4e9b\u7279\u5b9a\u7684\u89d2\u5ea6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u6570\u503c\u7cbe\u5ea6\u95ee\u9898\u3002\u8fd9\u662f\u7531\u4e8e\u8ba1\u7b97\u673a\u5728\u5904\u7406\u6d6e\u70b9\u6570\u65f6\u7684\u7cbe\u5ea6\u9650\u5236\u3002\u901a\u5e38\uff0c\u8fd9\u4e0d\u4f1a\u5bf9\u5927\u591a\u6570\u5e94\u7528\u4ea7\u751f\u5f71\u54cd\uff0c\u4f46\u5728\u9700\u8981\u9ad8\u7cbe\u5ea6\u8ba1\u7b97\u7684\u573a\u5408\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528Python\u7684<code>decimal<\/code>\u5e93\u6765\u63d0\u9ad8\u7cbe\u5ea6\u3002<\/p>\n<\/p>\n<p><h3>\u6027\u80fd\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0c<code>numpy<\/code>\u7684\u6027\u80fd\u4f18\u4e8e<code>math<\/code>\u5e93\uff0c\u8fd9\u662f\u56e0\u4e3a<code>numpy<\/code>\u5728\u5e95\u5c42\u4f7f\u7528\u4e86\u66f4\u9ad8\u6548\u7684\u6570\u7ec4\u8fd0\u7b97\u3002\u5982\u679c\u4f60\u53d1\u73b0\u8ba1\u7b97\u901f\u5ea6\u8f83\u6162\uff0c\u53ef\u4ee5\u8003\u8651\u5c06\u6570\u636e\u8f6c\u6362\u4e3a<code>numpy<\/code>\u6570\u7ec4\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u4ecb\u7ecd\uff0c\u4f60\u5e94\u8be5\u80fd\u591f\u4f7f\u7528Python\u8f7b\u677e\u8ba1\u7b97\u548c\u8f93\u51fasin(x)\u7684\u503c\uff0c\u5e76\u6839\u636e\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\u548c\u65b9\u6cd5\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u7406\u89e3\u548c\u638c\u63e1\u8fd9\u4e9b\u57fa\u7840\u8ba1\u7b97\u65b9\u6cd5\u80fd\u4e3a\u4f60\u7684\u9879\u76ee\u63d0\u4f9b\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8ba1\u7b97sin(x)\u7684\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528math\u6a21\u5757\u6765\u8ba1\u7b97sin(x)\u7684\u503c\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5bfc\u5165math\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528math.sin()\u51fd\u6570\u3002\u8bf7\u6ce8\u610f\uff0c\u8f93\u5165\u503c\u5e94\u8be5\u662f\u5f27\u5ea6\u3002\u5982\u679c\u60a8\u60f3\u8ba1\u7b97\u89d2\u5ea6\u7684\u6b63\u5f26\u503c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528math.radians()\u51fd\u6570\u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">import math\n\nangle_in_degrees = 30\nangle_in_radians = math.radians(angle_in_degrees)\nsine_value = math.sin(angle_in_radians)\nprint(sine_value)\n<\/code><\/pre>\n<p><strong>Python\u4e2d\u6709\u5176\u4ed6\u5e93\u53ef\u4ee5\u8ba1\u7b97sin(x)\u5417\uff1f<\/strong><br \/>\u9664\u4e86math\u6a21\u5757\uff0cPython\u7684NumPy\u5e93\u4e5f\u63d0\u4f9b\u4e86sin\u51fd\u6570\uff0c\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u66f4\u590d\u6742\u7684\u6570\u5b66\u64cd\u4f5c\u3002\u4f7f\u7528NumPy\u65f6\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u4f20\u5165\u5f27\u5ea6\u503c\u6216\u6570\u7ec4\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">import numpy as np\n\nangles = np.array([0, np.pi\/6, np.pi\/4, np.pi\/3])\nsine_values = np.sin(angles)\nprint(sine_values)\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u5bf9\u5e94\u89d2\u5ea6\u6b63\u5f26\u503c\u7684\u6570\u7ec4\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406sin(x)\u7684\u8d1f\u503c\u6216\u5927\u4e8e360\u5ea6\u7684\u89d2\u5ea6\uff1f<\/strong><br \/>sin\u51fd\u6570\u7684\u8f93\u51fa\u8303\u56f4\u662f[-1, 1]\uff0c\u56e0\u6b64\u65e0\u8bba\u8f93\u5165\u662f\u4ec0\u4e48\uff0c\u8f93\u51fa\u59cb\u7ec8\u5728\u6b64\u8303\u56f4\u5185\u3002\u5982\u679c\u60a8\u8f93\u5165\u7684\u89d2\u5ea6\u5927\u4e8e360\u5ea6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6a21\u8fd0\u7b97\uff08%\uff09\u6765\u5c06\u89d2\u5ea6\u8f6c\u6362\u52300\u5230360\u5ea6\u4e4b\u95f4\uff1a  <\/p>\n<pre><code class=\"language-python\">import math\n\nangle = 450  # 450\u5ea6\nnormalized_angle = angle % 360\nsine_value = math.sin(math.radians(normalized_angle))\nprint(sine_value)\n<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u60a8\u5f97\u5230\u6b63\u786e\u7684\u6b63\u5f26\u503c\u3002\u540c\u65f6\uff0c\u8d1f\u503c\u89d2\u5ea6\u4e5f\u53ef\u4ee5\u91c7\u7528\u76f8\u540c\u7684\u65b9\u6cd5\u5904\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u8f93\u51fasin(x)\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684math\u5e93\u6216numpy\u5e93\u3002 math\u5e93\u9002\u7528\u4e8e\u6807\u91cf [&hellip;]","protected":false},"author":3,"featured_media":985515,"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\/985504"}],"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=985504"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985504\/revisions"}],"predecessor-version":[{"id":985520,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985504\/revisions\/985520"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/985515"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=985504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=985504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=985504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}