</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>