1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

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

        共 1432字,需瀏覽 3分鐘

         ·

        2021-01-30 19:42

        點擊上方“公眾號”可訂閱哦!



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


        變量通過?tf.Variable?類進行創(chuàng)建和跟蹤。tf.Variable?表示張量,對它執(zhí)行運算可以改變其值。利用特定運算可以讀取和修改此張量的值。更高級的庫(如?tf.keras)使用?tf.Variable?來存儲模型參數(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])


        變量與張量的定義方式和操作行為都十分相似,實際上,它們都是?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ù)期運行,不過變量無法重構(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)




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

        點擊上方“藍字”關(guān)注本公眾號

        點擊上方“藍字”關(guān)注本公眾號

        ?END

        掃碼關(guān)注

        微信號|sdxx_rmbj


        瀏覽 36
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            成熟少妇精油按摩在线观看 | 毛片基地视频 | 日本熟妇在线播放 | 国产va视频 | 性爱777 | 色综合色综合网色综合 | 性猛交XXXX乱大交孕妇印度 | 免费站看大成人 | 欧美熟妇精品一区二区蜜桃视频 | 日本三级美国三级久久 |