当前位置:网站首页>Data types in tensorflow
Data types in tensorflow
2022-06-23 07:17:00 【Wanderer001】
Reference resources TensorFlow Data types in - cloud + Community - Tencent cloud
One 、Python Primitive types
TensorFlow To accept the Python Own native data types , for example Python Boolean type in , Numerical data type ( Integers , Floating point numbers ) And string type . The single value will be converted to 0 D tensor ( Scalar ), The list value will be converted to 1 D tensor ( vector ), The list set list will be converted to 2 D tensor ( matrix ) wait , The following example comes from TensorFlow for Machine Intelligence.
t_0 = 19 # Treated as a 0-d tensor, or "scalar"
tf.zeros_like(t_0) # ==> 0
tf.ones_like(t_0) # ==> 1
t_1 = [b"apple", b"peach", b"grape"] # treated as a 1-d tensor, or "vector"
tf.zeros_like(t_1) # ==> [b'' b'' b'']
tf.ones_like(t_1) # ==> TypeError
t_2 = [[True, False, False],
[False, False, True],
[False, True, False]] # treated as a 2-d tensor, or "matrix"
tf.zeros_like(t_2) # ==> 3x3 tensor, all elements are False
tf.ones_like(t_2) # ==> 3x3 tensor, all elements are TrueTwo 、TensorFlow Primitive types
It's like Numpy equally ,TensorFlow It also has its own data type , Will you be in TensorFlow You can see things like tf.int32, tf.float32 In addition to these , There are also some interesting data types, such as tf.bfloat, tf.complex, tf.quint. Here is the whole TensorFlow data type , The screenshot from tf.DType

3、 ... and 、Numpy data type
You may have noticed Numpy and TensorFlow There are many similarities .TensorFlow At the beginning of design, I hope to be able to communicate with Numpy It has a good integration effect .Numpy Software packages have now become the universal language of data science .
TensorFlow Many data types are also based on Numpy Of , in fact , If you make np.int32==tf.int32 Will return True. You can also pass it directly Numpy Data types are given directly to TensorFlow Medium ops.
tf.ones([2, 2], np.float32) ==> [[1.0 1.0], [1.0 1.0]]Please remember , Our good friends tf.Session.run(), The required input object is a Tensor But its output is a Numpy Array . in fact , On most occasions , You can use... At the same time TensorFlow The type and Numpy type .
边栏推荐
- 都是硬盘分区 C盘和D盘到底有什么区别?
- Quartz调度框架的学习使用
- 20220620 uniformly completely observable (UCO)
- About SQL: is there a way to fill in the null value in the field without adding fields on the basis of the original fields
- 316. 去除重复字母
- 312. poke the balloon
- How to achieve efficient network information dissemination
- C DPI adaptation problem
- TensorFlow中的数据类型
- ‘latin-1‘ codec can‘t encode characters in position 103-115: Body (‘一串中文‘) is not valid Latin-1
猜你喜欢

Quartz调度框架的学习使用

MySQL(四) — MySQL存储引擎

深度学习系列46:人脸图像超分GFP-GAN

Analysis of personalized learning progress in maker Education

In depth learning series 46: face image super score gfp-gan

excel高级绘图技巧100讲(八)-Excel绘制WIFI图

Advanced drawing skills of Excel lecture 100 (VIII) -excel drawing WiFi diagram

Regular expression graph and text ultra detailed summary without rote memorization (Part 1)

【博弈论】基础知识

GloRe
随机推荐
312. 戳气球
Xshell7 Download
315. 计算右侧小于当前元素的个数
897. 递增顺序搜索树
启发式的搜索策略
How flannel works
1161 Merging Linked Lists
GloRe
100 GIS practical application cases (79) - key points of making multi plan integrated base map
codeforce 158B Taxi
303. region and retrieval - array immutable
322. change exchange
20220620 uniformly completely observable (UCO)
SSM整合
闫氏DP分析法
初始化层实现
JUnit unit test reports an error org junit. runners. model. InvalidTestClassError: Invalid test class ‘xxx‘ . No runnable meth
20220621 Three Conjugates of Dual Quaternions
正则表达式图文超详细总结不用死记硬背(上篇)
【博弈论】基础知识