{"id":1085936,"date":"2025-01-08T13:20:59","date_gmt":"2025-01-08T05:20:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1085936.html"},"modified":"2025-01-08T13:21:01","modified_gmt":"2025-01-08T05:21:01","slug":"python%e5%a6%82%e4%bd%95%e8%bf%9b%e8%a1%8c%e5%90%91%e9%87%8f%e5%8f%89%e4%b9%98-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1085936.html","title":{"rendered":"python\u5982\u4f55\u8fdb\u884c\u5411\u91cf\u53c9\u4e58"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24195606\/fc63c382-4006-490c-90d2-24aa7d95c78d.webp\" alt=\"python\u5982\u4f55\u8fdb\u884c\u5411\u91cf\u53c9\u4e58\" \/><\/p>\n<p><p> <strong>Python\u8fdb\u884c\u5411\u91cf\u53c9\u4e58\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528Numpy\u5e93\u3001\u624b\u52a8\u5b9e\u73b0\u53c9\u4e58\u516c\u5f0f\u3001\u6216\u4f7f\u7528\u5176\u4ed6\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u5982SciPy\u3002\u6700\u7b80\u4fbf\u7684\u65b9\u6cd5\u662f\u4f7f\u7528Numpy\u5e93\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u5411\u91cf\u8fd0\u7b97\u51fd\u6570\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4f7f\u7528Numpy\u5e93\u8fdb\u884c\u5411\u91cf\u53c9\u4e58<\/h3>\n<\/p>\n<p><p>Numpy\u5e93\u662fPython\u4e2d\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684\u6838\u5fc3\u5e93\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u5b66\u51fd\u6570\u548c\u9ad8\u6548\u7684\u6570\u7ec4\u5904\u7406\u529f\u80fd\u3002\u4f7f\u7528Numpy\u8fdb\u884c\u5411\u91cf\u53c9\u4e58\u975e\u5e38\u7b80\u5355\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u5b9a\u4e49\u4e24\u4e2a\u5411\u91cf<\/strong><\/h2>\n<p>vector_a = np.array([1, 2, 3])<\/p>\n<p>vector_b = np.array([4, 5, 6])<\/p>\n<h2><strong>\u8ba1\u7b97\u5411\u91cf\u53c9\u4e58<\/strong><\/h2>\n<p>cross_product = np.cross(vector_a, vector_b)<\/p>\n<p>print(&quot;\u5411\u91cf\u53c9\u4e58\u7ed3\u679c:&quot;, cross_product)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u624b\u52a8\u5b9e\u73b0\u5411\u91cf\u53c9\u4e58\u516c\u5f0f<\/h3>\n<\/p>\n<p><p>\u5411\u91cf\u53c9\u4e58\u7684\u516c\u5f0f\u4e3a\uff1a<\/p>\n<p>[ \\mathbf{a} \\times \\mathbf{b} = (a_2b_3 &#8211; a_3b_2, a_3b_1 &#8211; a_1b_3, a_1b_2 &#8211; a_2b_1) ]<\/p>\n<p>\u6839\u636e\u8fd9\u4e2a\u516c\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u624b\u52a8\u5b9e\u73b0\u5411\u91cf\u53c9\u4e58\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def cross_product_manual(vector_a, vector_b):<\/p>\n<p>    result = [<\/p>\n<p>        vector_a[1] * vector_b[2] - vector_a[2] * vector_b[1],<\/p>\n<p>        vector_a[2] * vector_b[0] - vector_a[0] * vector_b[2],<\/p>\n<p>        vector_a[0] * vector_b[1] - vector_a[1] * vector_b[0]<\/p>\n<p>    ]<\/p>\n<p>    return result<\/p>\n<p>vector_a = [1, 2, 3]<\/p>\n<p>vector_b = [4, 5, 6]<\/p>\n<p>cross_product = cross_product_manual(vector_a, vector_b)<\/p>\n<p>print(&quot;\u624b\u52a8\u8ba1\u7b97\u7684\u5411\u91cf\u53c9\u4e58\u7ed3\u679c:&quot;, cross_product)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f7f\u7528SciPy\u5e93\u8fdb\u884c\u5411\u91cf\u53c9\u4e58<\/h3>\n<\/p>\n<p><p>SciPy\u5e93\u4e5f\u662fPython\u4e2d\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u5b83\u5efa\u7acb\u5728Numpy\u7684\u57fa\u7840\u4e0a\uff0c\u5e76\u63d0\u4f9b\u4e86\u66f4\u591a\u9ad8\u7ea7\u7684\u6570\u5b66\u51fd\u6570\u3002\u4f7f\u7528SciPy\u8fdb\u884c\u5411\u91cf\u53c9\u4e58\u7684\u65b9\u5f0f\u4e0eNumpy\u7c7b\u4f3c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from scipy.spatial import distance<\/p>\n<h2><strong>\u5b9a\u4e49\u4e24\u4e2a\u5411\u91cf<\/strong><\/h2>\n<p>vector_a = np.array([1, 2, 3])<\/p>\n<p>vector_b = np.array([4, 5, 6])<\/p>\n<h2><strong>\u8ba1\u7b97\u5411\u91cf\u53c9\u4e58<\/strong><\/h2>\n<p>cross_product = np.cross(vector_a, vector_b)<\/p>\n<p>print(&quot;\u4f7f\u7528SciPy\u8ba1\u7b97\u7684\u5411\u91cf\u53c9\u4e58\u7ed3\u679c:&quot;, cross_product)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5411\u91cf\u53c9\u4e58\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5411\u91cf\u53c9\u4e58\u5728\u8ba1\u7b97\u51e0\u4f55\u3001\u7269\u7406\u5b66\u548c\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u4e2d\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002<strong>\u5728\u7269\u7406\u5b66\u4e2d\uff0c\u5411\u91cf\u53c9\u4e58\u7528\u4e8e\u8ba1\u7b97\u529b\u77e9\u548c\u89d2\u52a8\u91cf\uff1b\u5728\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u4e2d\uff0c\u5411\u91cf\u53c9\u4e58\u7528\u4e8e\u8ba1\u7b97\u6cd5\u7ebf\u5411\u91cf\u548c\u786e\u5b9a\u591a\u8fb9\u5f62\u7684\u671d\u5411\u3002<\/strong>\u5411\u91cf\u53c9\u4e58\u7684\u7ed3\u679c\u662f\u4e00\u4e2a\u5782\u76f4\u4e8e\u4e24\u4e2a\u8f93\u5165\u5411\u91cf\u7684\u5411\u91cf\uff0c\u5176\u65b9\u5411\u7531\u53f3\u624b\u5b9a\u5219\u786e\u5b9a\uff0c\u5927\u5c0f\u7b49\u4e8e\u4e24\u4e2a\u8f93\u5165\u5411\u91cf\u6240\u5939\u89d2\u7684\u6b63\u5f26\u503c\u4e58\u4ee5\u4e24\u4e2a\u5411\u91cf\u7684\u6a21\u957f\u3002<\/p>\n<\/p>\n<p><h3>\u5411\u91cf\u53c9\u4e58\u7684\u6027\u8d28<\/h3>\n<\/p>\n<p><p>\u5411\u91cf\u53c9\u4e58\u5177\u6709\u4ee5\u4e0b\u51e0\u4e2a\u91cd\u8981\u6027\u8d28\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u53cd\u4ea4\u6362\u6027\uff1a<\/strong> (\\mathbf{a} \\times \\mathbf{b} = -(\\mathbf{b} \\times \\mathbf{a}))<\/li>\n<li><strong>\u5206\u914d\u5f8b\uff1a<\/strong> (\\mathbf{a} \\times (\\mathbf{b} + \\mathbf{c}) = \\mathbf{a} \\times \\mathbf{b} + \\mathbf{a} \\times \\mathbf{c})<\/li>\n<li><strong>\u4e0e\u6807\u91cf\u7684\u7ed3\u5408\u6027\uff1a<\/strong> (k (\\mathbf{a} \\times \\mathbf{b}) = (k\\mathbf{a}) \\times \\mathbf{b} = \\mathbf{a} \\times (k\\mathbf{b}))<\/li>\n<li><strong>\u5411\u91cf\u53c9\u4e58\u7684\u7ed3\u679c\u5782\u76f4\u4e8e\u8f93\u5165\u5411\u91cf\uff1a<\/strong> (\\mathbf{a} \\times \\mathbf{b} \\perp \\mathbf{a})\uff0c(\\mathbf{a} \\times \\mathbf{b} \\perp \\mathbf{b})<\/li>\n<\/ol>\n<p><h3>\u5411\u91cf\u53c9\u4e58\u7684\u51e0\u4f55\u89e3\u91ca<\/h3>\n<\/p>\n<p><p>\u5411\u91cf\u53c9\u4e58\u7684\u7ed3\u679c\u662f\u4e00\u4e2a\u5411\u91cf\uff0c\u5176\u65b9\u5411\u7531\u53f3\u624b\u5b9a\u5219\u786e\u5b9a\u3002\u53f3\u624b\u5b9a\u5219\u8bf4\u660e\uff0c\u5982\u679c\u5c06\u53f3\u624b\u7684\u98df\u6307\u6307\u5411\u7b2c\u4e00\u4e2a\u5411\u91cf\uff08(\\mathbf{a})\uff09\uff0c\u4e2d\u6307\u6307\u5411\u7b2c\u4e8c\u4e2a\u5411\u91cf\uff08(\\mathbf{b})\uff09\uff0c\u90a3\u4e48\u5927\u62c7\u6307\u6307\u5411\u7684\u65b9\u5411\u5c31\u662f\u5411\u91cf\u53c9\u4e58\u7684\u7ed3\u679c\u65b9\u5411\u3002<\/p>\n<\/p>\n<p><p>\u5411\u91cf\u53c9\u4e58\u7684\u5927\u5c0f\u7b49\u4e8e\u4e24\u4e2a\u5411\u91cf\u6240\u5939\u89d2\u7684\u6b63\u5f26\u503c\u4e58\u4ee5\u4e24\u4e2a\u5411\u91cf\u7684\u6a21\u957f\uff0c\u5373\uff1a<\/p>\n<p>[ |\\mathbf{a} \\times \\mathbf{b}| = |\\mathbf{a}| |\\mathbf{b}| \\sin(\\theta) ]<\/p>\n<p>\u5176\u4e2d\uff0c(\\theta) \u662f\u4e24\u4e2a\u5411\u91cf\u4e4b\u95f4\u7684\u5939\u89d2\u3002<\/p>\n<\/p>\n<p><h3>\u5411\u91cf\u53c9\u4e58\u5728\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u4e2d\uff0c\u5411\u91cf\u53c9\u4e58\u5e38\u7528\u4e8e\u8ba1\u7b97\u6cd5\u7ebf\u5411\u91cf\uff0c\u8fd9\u5bf9\u4e8e\u5149\u7167\u8ba1\u7b97\u548c\u78b0\u649e\u68c0\u6d4b\u975e\u5e38\u91cd\u8981\u3002\u6cd5\u7ebf\u5411\u91cf\u662f\u4e00\u4e2a\u5782\u76f4\u4e8e\u8868\u9762\u7684\u5411\u91cf\uff0c\u7528\u4e8e\u786e\u5b9a\u8868\u9762\u7684\u671d\u5411\u3002\u901a\u8fc7\u8ba1\u7b97\u4e24\u4e2a\u76f8\u4ea4\u8fb9\u7684\u5411\u91cf\u53c9\u4e58\uff0c\u53ef\u4ee5\u5f97\u5230\u8868\u9762\u7684\u6cd5\u7ebf\u5411\u91cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def calculate_normal(p1, p2, p3):<\/p>\n<p>    # \u8ba1\u7b97\u4e24\u4e2a\u8fb9\u5411\u91cf<\/p>\n<p>    u = np.array(p2) - np.array(p1)<\/p>\n<p>    v = np.array(p3) - np.array(p1)<\/p>\n<p>    # \u8ba1\u7b97\u6cd5\u7ebf\u5411\u91cf<\/p>\n<p>    normal = np.cross(u, v)<\/p>\n<p>    return normal<\/p>\n<h2><strong>\u5b9a\u4e49\u4e09\u4e2a\u9876\u70b9<\/strong><\/h2>\n<p>p1 = [1, 0, 0]<\/p>\n<p>p2 = [0, 1, 0]<\/p>\n<p>p3 = [0, 0, 1]<\/p>\n<h2><strong>\u8ba1\u7b97\u6cd5\u7ebf\u5411\u91cf<\/strong><\/h2>\n<p>normal_vector = calculate_normal(p1, p2, p3)<\/p>\n<p>print(&quot;\u6cd5\u7ebf\u5411\u91cf:&quot;, normal_vector)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5411\u91cf\u53c9\u4e58\u7684\u7269\u7406\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u7269\u7406\u5b66\u4e2d\uff0c\u5411\u91cf\u53c9\u4e58\u7528\u4e8e\u8ba1\u7b97\u529b\u77e9\u548c\u89d2\u52a8\u91cf\u3002\u529b\u77e9\u662f\u4e00\u4e2a\u7269\u4f53\u7ed5\u67d0\u4e2a\u70b9\u65cb\u8f6c\u7684\u529b\u91cf\uff0c\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1a<\/p>\n<p>[ \\mathbf{M} = \\mathbf{r} \\times \\mathbf{F} ]<\/p>\n<p>\u5176\u4e2d\uff0c(\\mathbf{M}) \u662f\u529b\u77e9\uff0c(\\mathbf{r}) \u662f\u529b\u7684\u4f5c\u7528\u70b9\u5230\u65cb\u8f6c\u70b9\u7684\u8ddd\u79bb\u5411\u91cf\uff0c(\\mathbf{F}) \u662f\u4f5c\u7528\u529b\u3002<\/p>\n<\/p>\n<p><p>\u89d2\u52a8\u91cf\u662f\u7269\u4f53\u7ed5\u67d0\u4e2a\u70b9\u65cb\u8f6c\u7684\u52a8\u91cf\uff0c\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1a<\/p>\n<p>[ \\mathbf{L} = \\mathbf{r} \\times \\mathbf{p} ]<\/p>\n<p>\u5176\u4e2d\uff0c(\\mathbf{L}) \u662f\u89d2\u52a8\u91cf\uff0c(\\mathbf{r}) \u662f\u7269\u4f53\u7684\u4f4d\u7f6e\u5411\u91cf\uff0c(\\mathbf{p}) \u662f\u7ebf\u52a8\u91cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def calculate_torque(r, F):<\/p>\n<p>    # \u8ba1\u7b97\u529b\u77e9<\/p>\n<p>    torque = np.cross(r, F)<\/p>\n<p>    return torque<\/p>\n<p>def calculate_angular_momentum(r, p):<\/p>\n<p>    # \u8ba1\u7b97\u89d2\u52a8\u91cf<\/p>\n<p>    angular_momentum = np.cross(r, p)<\/p>\n<p>    return angular_momentum<\/p>\n<h2><strong>\u5b9a\u4e49\u4f4d\u7f6e\u5411\u91cf\u548c\u529b\u5411\u91cf<\/strong><\/h2>\n<p>r = [1, 0, 0]<\/p>\n<p>F = [0, 1, 0]<\/p>\n<h2><strong>\u8ba1\u7b97\u529b\u77e9<\/strong><\/h2>\n<p>torque = calculate_torque(r, F)<\/p>\n<p>print(&quot;\u529b\u77e9:&quot;, torque)<\/p>\n<h2><strong>\u5b9a\u4e49\u4f4d\u7f6e\u5411\u91cf\u548c\u52a8\u91cf\u5411\u91cf<\/strong><\/h2>\n<p>p = [0, 1, 0]<\/p>\n<h2><strong>\u8ba1\u7b97\u89d2\u52a8\u91cf<\/strong><\/h2>\n<p>angular_momentum = calculate_angular_momentum(r, p)<\/p>\n<p>print(&quot;\u89d2\u52a8\u91cf:&quot;, angular_momentum)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5411\u91cf\u53c9\u4e58\u7684\u5b9e\u73b0\u7ec6\u8282<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u73b0\u5411\u91cf\u53c9\u4e58\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u5411\u91cf\u7684\u7ef4\u6570\uff1a<\/strong> \u5411\u91cf\u53c9\u4e58\u901a\u5e38\u5e94\u7528\u4e8e\u4e09\u7ef4\u5411\u91cf\uff0c\u4f46\u4e5f\u53ef\u4ee5\u6269\u5c55\u5230\u66f4\u9ad8\u7ef4\u5ea6\u3002\u5728\u4e09\u7ef4\u7a7a\u95f4\u4e2d\uff0c\u5411\u91cf\u53c9\u4e58\u7684\u7ed3\u679c\u662f\u4e00\u4e2a\u4e09\u7ef4\u5411\u91cf\u3002<\/li>\n<li><strong>\u5411\u91cf\u7684\u987a\u5e8f\uff1a<\/strong> \u5411\u91cf\u53c9\u4e58\u662f\u975e\u4ea4\u6362\u7684\uff0c\u5373(\\mathbf{a} \\times \\mathbf{b} \\neq \\mathbf{b} \\times \\mathbf{a})\uff0c\u800c\u662f(\\mathbf{a} \\times \\mathbf{b} = -(\\mathbf{b} \\times \\mathbf{a}))\u3002<\/li>\n<li><strong>\u8ba1\u7b97\u6548\u7387\uff1a<\/strong> \u4f7f\u7528Numpy\u5e93\u53ef\u4ee5\u5927\u5e45\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u5927\u89c4\u6a21\u5411\u91cf\u8fd0\u7b97\u3002<\/li>\n<\/ol>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5411\u91cf\u53c9\u4e58\u662f\u5411\u91cf\u8fd0\u7b97\u4e2d\u4e00\u4e2a\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u7269\u7406\u5b66\u3001\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u548c\u5de5\u7a0b\u9886\u57df\u3002\u4f7f\u7528Numpy\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u5411\u91cf\u53c9\u4e58\uff0c\u540c\u65f6\u638c\u63e1\u5411\u91cf\u53c9\u4e58\u7684\u624b\u52a8\u8ba1\u7b97\u65b9\u6cd5\u548c\u51e0\u4f55\u89e3\u91ca\uff0c\u6709\u52a9\u4e8e\u6df1\u5165\u7406\u89e3\u5411\u91cf\u8fd0\u7b97\u7684\u539f\u7406\u548c\u5e94\u7528\u3002\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\u548c\u793a\u4f8b\uff0c\u4f60\u53ef\u4ee5\u5728Python\u4e2d\u9ad8\u6548\u5730\u8fdb\u884c\u5411\u91cf\u53c9\u4e58\uff0c\u5e76\u5e94\u7528\u4e8e\u5b9e\u9645\u95ee\u9898\u7684\u89e3\u51b3\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5411\u91cf\u53c9\u4e58\u5728Python\u4e2d\u5982\u4f55\u5b9e\u73b0\uff1f<\/strong><\/p>\n<p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u8fdb\u884c\u5411\u91cf\u7684\u53c9\u4e58\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86NumPy\u5e93\u3002\u4f7f\u7528<code>numpy.cross()<\/code>\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u8ba1\u7b97\u4e24\u4e2a\u5411\u91cf\u7684\u53c9\u4e58\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u5b9a\u4e49\u4e24\u4e2a\u5411\u91cf\na = np.array([1, 2, 3])\nb = np.array([4, 5, 6])\n\n# \u8ba1\u7b97\u53c9\u4e58\ncross_product = np.cross(a, b)\nprint(cross_product)\n<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u5f97\u5230\u5411\u91cfa\u548cb\u7684\u53c9\u4e58\u7ed3\u679c\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u8fdb\u884c\u5411\u91cf\u53c9\u4e58\u65f6\uff0c\u6709\u54ea\u4e9b\u6ce8\u610f\u4e8b\u9879\uff1f<\/strong><\/p>\n<p>\u5728\u8fdb\u884c\u5411\u91cf\u53c9\u4e58\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u5411\u91cf\u7684\u7ef4\u5ea6\u3002\u53c9\u4e58\u4ec5\u9002\u7528\u4e8e\u4e09\u7ef4\u5411\u91cf\uff0c\u56e0\u6b64\u786e\u4fdd\u8f93\u5165\u7684\u6570\u7ec4\u662f\u5f62\u72b6\u4e3a(3,)\u7684\u5411\u91cf\u3002\u6b64\u5916\uff0c\u7ed3\u679c\u7684\u65b9\u5411\u4e0e\u8f93\u5165\u5411\u91cf\u7684\u987a\u5e8f\u6709\u5173\uff0c\u4ea4\u6362\u4e24\u4e2a\u5411\u91cf\u5c06\u5f97\u5230\u7ed3\u679c\u7684\u76f8\u53cd\u65b9\u5411\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u624b\u52a8\u5b9e\u73b0\u5411\u91cf\u7684\u53c9\u4e58\u800c\u4e0d\u4f9d\u8d56\u4e8e\u5e93\uff1f<\/strong><\/p>\n<p>\u5f53\u7136\u53ef\u4ee5\uff01\u5982\u679c\u4e0d\u60f3\u4f7f\u7528NumPy\u5e93\uff0c\u53ef\u4ee5\u624b\u52a8\u5b9e\u73b0\u5411\u91cf\u7684\u53c9\u4e58\u3002\u53c9\u4e58\u7684\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p>\u5bf9\u4e8e\u5411\u91cf ( \\mathbf{a} = (a_1, a_2, a_3) ) \u548c ( \\mathbf{b} = (b_1, b_2, b_3) )\uff0c\u53c9\u4e58\u7ed3\u679c\u4e3a\uff1a<\/p>\n<p>[<br \/>\n\\mathbf{a} \\times \\mathbf{b} = (a_2b_3 &#8211; a_3b_2, a_3b_1 &#8211; a_1b_3, a_1b_2 &#8211; a_2b_1)<br \/>\n]<\/p>\n<p>\u4ee5\u4e0b\u662f\u624b\u52a8\u5b9e\u73b0\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">def cross_product(a, b):\n    return (\n        a[1] * b[2] - a[2] * b[1],\n        a[2] * b[0] - a[0] * b[2],\n        a[0] * b[1] - a[1] * b[0]\n    )\n\n# \u793a\u4f8b\u5411\u91cf\na = (1, 2, 3)\nb = (4, 5, 6)\n\nresult = cross_product(a, b)\nprint(result)\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u60a8\u53ef\u4ee5\u5728\u4e0d\u4f9d\u8d56\u4efb\u4f55\u5916\u90e8\u5e93\u7684\u60c5\u51b5\u4e0b\u5b9e\u73b0\u53c9\u4e58\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u8fdb\u884c\u5411\u91cf\u53c9\u4e58\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528Numpy\u5e93\u3001\u624b\u52a8\u5b9e\u73b0\u53c9\u4e58\u516c\u5f0f\u3001\u6216\u4f7f\u7528\u5176\u4ed6\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u5982Sc [&hellip;]","protected":false},"author":3,"featured_media":1085944,"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\/1085936"}],"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=1085936"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1085936\/revisions"}],"predecessor-version":[{"id":1085946,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1085936\/revisions\/1085946"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1085944"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1085936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1085936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1085936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}