【TensorFlow】自学笔迹 | 框架的知识点

Tensor
Tensor(张量)
  • 不断流动的东西就是张量。节点就是operation计算
  • 维度是0的话,是一个标量(Scalar)
    numpy中的基础要素就是array,和Tensor 差不多的一种表述
import numpy as np
zeros = np.zeros((3,4))
zeros

ones = np.ones((5,6))
ones

# 对角矩阵: 必须是一个方阵.对角线是1,其他都是0的方阵
ident = np.eye(4)

Tensors(张量)
Tensor属性
  • 数据类型dtype
  • 形状Shape
  • 其他
官方Tensor介绍:
https://www.tensorflow.org/api_docs/python/tf/Tensor

4种重要Tensor:

  1. Constant
  2. Variable
  3. Placeholder
  4. SparseTensor
  • Constant

定义在tf.constant

tf.constant(
    value,
    dtype=None,
    shape=None,
    name='Const',
    verify_shape=False
)

数值:标量,向量,矩阵

verify_shape 验证形状

官网例子:

# Constant 1-D Tensor populated with value list.
tensor = tf.constant([1, 2, 3, 4, 5, 6, 7]) => [1 2 3 4 5 6 7]

# Constant 2-D tensor populated with scalar value -1.
tensor = tf.constant(-1.0, shape=[2, 3]) => [[-1. -1. -1.]
                                             [-1. -1. -1.]]

代码演示:

const = tf.constant(3)
const 
# 输出const:0 shape=() dtype=int32
  • run之后才能得到具体的数
  • 普通的变量常量比较不一样

你可能感兴趣的:(【TensorFlow】自学笔迹 | 框架的知识点)