TensorFlow的用途 张量 定义框架和处理数据。一种 tensor conceptualized multidimensions vectors and matrices. Mathematically, a 张量 is a geometric 目的 that maps in a multi-linear manner geometric vectors, scalars, and another 张量(s) to a resulting 张量.
秩 | 实体 |
0 | 标量 |
1 | 向量 |
2 | 矩阵 |
3 | 3张量 |
n | 正弦张量 |
这些张量对象用于实现Graph对象,这些对象之间相互协调以产生所需的结果。张量(tf.Tensor)对象具有以下两个基本属性:“Data Type” and “Shape”。张量中的每个元素都具有相同的数据类型,并且该数据类型始终是已知的。形状(即它具有的维数和每个维的大小)可能仅是部分已知的。如果输入的形状也完全已知,则大多数操作会产生形状已知的张量,但在某些情况下,’仅在图执行时才能找到张量的形状。除此之外,还有其他可能的变量。
张量等级(尺寸)
秩 of 张量 is the actual dimension of the database. The 张量 shape represents the size of each dimension. A 0 rank means zero dimension and represents scalar quantity.
fruit = tf.Variable(" 苹果 ", tf.string)
Count = tf.Variable(100, tf.int16)
Weight = tf.Variable(3.14159265359, tf.float64)
等级1表示一个维度,即一个项目列表。
Names = tf.Variable(["Nilesh","Akash","Ritesh"], tf.string)
Weights = tf.Variable([100, 110], tf.float32)
GPA = tf.Variable([4,3], tf.int32)
等级2表示作为列表列表的2D数组。
Students = tf.Variable([["Nilesh"],["Ritesh"]], tf
.string)
Ages = tf.Variable([[25],[26]], tf.int16)
Tall = tf.Variable([[False], [True]], tf.bool)
Rank of atf.Tensor
object
tf.rank方法可用于确定对象的等级。
r = tf.rank(Students)
# After the graph runs, r will hold the value 2.
例:
import 张量flow as tf
sess = tf.InteractiveSession()
Students = tf.Variable([["Nilesh"],["Ritesh"]], tf.string)
r = tf.rank(Students)
init = tf.global_variables_initializer()
with sess.as_default():
print_op = tf.print(r)
with tf.control_dependencies([print_op]):
out = tf.add(r, r)
sess.run(out)
with sess.as_default():
sess.run(init)
v = sess.run(Students)
print(v)
(venv) [[email protected] TENSORFLOW]$
Instructions for updating:
Colocations handled automatically by placer.
2
[[b'Nilesh']
[b'Ritesh']]
广告
