日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

tensorflow2.0 基础一 常用数据类型及转换

發布時間:2023/11/28 生活经验 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tensorflow2.0 基础一 常用数据类型及转换 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
版權聲明:本文為博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。 本文鏈接:https://blog.csdn.net/weixin_43619065/article/details/101080128
            </div><!--一個博主專欄付費入口--><!--一個博主專欄付費入口結束--><link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-4a3473df85.css"><div id="content_views" class="markdown_views prism-atelier-sulphurpool-light"><!-- flowchart 箭頭圖標 勿刪 --><svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path></svg><p></p><div class="toc"><h3><a name="t0"></a>目錄</h3><ul><li><a href="#Tensor__2" rel="nofollow" target="_self">Tensor 是什么</a></li><ul><li><a href="#TF_11" rel="nofollow" target="_self">TF數據類型</a></li><li><a href="#Create_Tensor_16" rel="nofollow" target="_self">Create Tensor</a></li><li><a href="#Tensor_Property_37" rel="nofollow" target="_self">Tensor Property</a></li><li><a href="#Check_Tensor_Type_40" rel="nofollow" target="_self">Check Tensor Type</a></li><li><a href="#Convert__43" rel="nofollow" target="_self">Convert 轉換</a></li><li><a href="#bool_int_46" rel="nofollow" target="_self">bool int</a></li><li><a href="#tfVariable_49" rel="nofollow" target="_self">tf.Variable</a></li><li><a href="#To_numpy_53" rel="nofollow" target="_self">To numpy</a></li></ul></ul></div><p></p>

Tensor 是什么

scalar: 1.1
vector: [1.1],[1.1,2.2,...]
matrix: [[1.1,2.2],[3.3,4.4],[5.5,6.6]]
tensor: rank > 2
  • 1
  • 2
  • 3
  • 4

以上都可以叫做tensor

TF數據類型

  • int, float, double
  • bool
  • string

Create Tensor

In[3]: tf.constant(1)
Out[3]: <tf.Tensor: id=0, shape=(), dtype=int32, numpy=1>

In[4]: tf.constant(1.)
Out[4]: <tf.Tensor: id=6, shape=(), dtype=float32, numpy=1.0>

In[5]: tf.constant(2.2,dtype=tf.int32)
Out[5]: TypeError: Cannot convert provided value to EagerTensor. Provided value: 2.2 Requested dtype: int32

In[6]: tf.constant(2., dtype=tf.double)
Out[6]: <tf.Tensor: id=25, shape=(), dtype=float64, numpy=2.0>

In[7]: tf.constant([True,False])
Out[7]: <tf.Tensor: id=39, shape=(2,), dtype=bool, numpy=array([ True, False])>

In[8]: tf.constant(‘hello, world.’)
Out[8]: <tf.Tensor: id=56, shape=(), dtype=string, numpy=b’hello, world.’>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

Tensor Property

Check Tensor Type

Convert 轉換

bool int

tf.Variable


特別注意tf.Variable 通過isinstance判斷是否為tensor會返回False,所以盡量使用tf.is_tensor。

To numpy

                                </div><link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet"></div>

總結

以上是生活随笔為你收集整理的tensorflow2.0 基础一 常用数据类型及转换的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。