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

2018-04-20  本文已影响0人  自动化丶智能小巫师
Tensor
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属性
官方Tensor介绍:
https://www.tensorflow.org/api_docs/python/tf/Tensor

4种重要Tensor:

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

定义在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
上一篇 下一篇

猜你喜欢

热点阅读