<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## 問題 你寫的最新的網絡認證方案代碼遇到了一個難題,并且你唯一的解決辦法就是使用復數空間。再或者是你僅僅需要使用復數來執行一些計算操作。 ## 解決方案 復數可以用使用函數 `complex(real, imag)` 或者是帶有后綴j的浮點數來指定。比如: >>> a = complex(2, 4) >>> b = 3 - 5j >>> a (2+4j) >>> b (3-5j) >>> 對應的實部、虛部和共軛復數可以很容易的獲取。就像下面這樣: >>> a.real 2.0 >>> a.imag 4.0 >>> a.conjugate() (2-4j) >>> 另外,所有常見的數學運算都可以工作: >>> a + b (5-1j) >>> a * b (26+2j) >>> a / b (-0.4117647058823529+0.6470588235294118j) >>> abs(a) 4.47213595499958 >>> 如果要執行其他的復數函數比如正弦、余弦或平方根,使用cmath模塊: >>> import cmath >>> cmath.sin(a) (24.83130584894638-11.356612711218174j) >>> cmath.cos(a) (-11.36423470640106-24.814651485634187j) >>> cmath.exp(a) (-4.829809383269385-5.5920560936409816j) >>> ## 討論 Python中大部分與數學相關的模塊都能處理復數。比如如果你使用numpy,可以很容易的構造一個復數數組并在這個數組上執行各種操作: >>> import numpy as np >>> a = np.array([2+3j, 4+5j, 6-7j, 8+9j]) >>> a array([ 2.+3.j, 4.+5.j, 6.-7.j, 8.+9.j]) >>> a + 2 array([ 4.+3.j, 6.+5.j, 8.-7.j, 10.+9.j]) >>> np.sin(a) array([ 9.15449915 -4.16890696j, -56.16227422 -48.50245524j, -153.20827755-526.47684926j, 4008.42651446-589.49948373j]) >>> Python的標準數學函數確實情況下并不能產生復數值,因此你的代碼中不可能會出現復數返回值。比如: >>> import math >>> math.sqrt(-1) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: math domain error >>> 如果你想生成一個復數返回結果,你必須顯示的使用cmath模塊,或者在某個支持復數的庫中聲明復數類型的使用。比如: >>> import cmath >>> cmath.sqrt(-1) 1j >>>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看