<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          【TensorFlow】筆記:基礎(chǔ)知識(shí)-變量

          共 1432字,需瀏覽 3分鐘

           ·

          2021-01-30 19:42

          點(diǎn)擊上方“公眾號(hào)”可訂閱哦!



          TensorFlow?變量是用于表示程序處理的共享持久狀態(tài)的推薦方法。本指南介紹在 TensorFlow 中如何創(chuàng)建、更新和管理?tf.Variable?的實(shí)例。


          變量通過(guò)?tf.Variable?類進(jìn)行創(chuàng)建和跟蹤。tf.Variable?表示張量,對(duì)它執(zhí)行運(yùn)算可以改變其值。利用特定運(yùn)算可以讀取和修改此張量的值。更高級(jí)的庫(kù)(如?tf.keras)使用?tf.Variable?來(lái)存儲(chǔ)模型參數(shù)。



          01

          創(chuàng)建變量


          創(chuàng)建變量

          import tensorflow as tfmy_tensor = tf.constant([[1.0, 2.0], [3.0, 4.0]])my_variable = tf.Variable(my_tensor)


          變量可以是各種類型,就像張量一樣

          bool_variable = tf.Variable([False, False, False, True])complex_variable = tf.Variable([5 + 4j, 6 + 1j])


          變量與張量的定義方式和操作行為都十分相似,實(shí)際上,它們都是?tf.Tensor?支持的一種數(shù)據(jù)結(jié)構(gòu)。與張量類似,變量也有?dtype?和形狀,并且可以導(dǎo)出至 NumPy。

          print("Shape: ",my_variable.shape)print("DType: ",my_variable.dtype)print("As NumPy: ", my_variable.numpy)
          # outputShape: (2, 2)DType: 'float32'>As NumPy: 'Variable:0' shape=(2, 2) dtype=float32, numpy=array([[1., 2.], [3., 4.]], dtype=float32)>>


          大部分張量運(yùn)算在變量上也可以按預(yù)期運(yùn)行,不過(guò)變量無(wú)法重構(gòu)形狀。

          print("A variable:",my_variable)print("\nViewed as a tensor:", tf.convert_to_tensor(my_variable))print("\nIndex of highest value:", tf.argmax(my_variable))
          # This creates a new tensor; it does not reshape the variable.print("\nCopying and reshaping: ", tf.reshape(my_variable, ([1,4]))
          # outputA variable: 'Variable:0' shape=(2, 2) dtype=float32, numpy=array([[1., 2.], [3., 4.]], dtype=float32)>
          Viewed as a tensor: tf.Tensor([[1. 2.] [3. 4.]], shape=(2, 2), dtype=float32)
          Index of highest value: tf.Tensor([1 1], shape=(2,), dtype=int64)
          Copying and reshaping: tf.Tensor([[1. 2. 3. 4.]], shape=(1, 4), dtype=float32)




          參考文獻(xiàn):文檔主要參考TensorFlow官網(wǎng)

          點(diǎn)擊上方“藍(lán)字”關(guān)注本公眾號(hào)

          點(diǎn)擊上方“藍(lán)字”關(guān)注本公眾號(hào)

          ?END

          掃碼關(guān)注

          微信號(hào)|sdxx_rmbj


          瀏覽 36
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产又爽又黄A片 | 欧美成人午夜无码A片秀色直播 | 蜜av在线 | 椎名空一区二区三区无码观看 | 精品视频一二三区 |