zoukankan      html  css  js  c++  java
  • Tensorflow--Tensor

    张量的维度(秩)

    tensor属性

    tensor和numpy类似,具有类似的属性,例如:

    数据类型dtpye

    形状shape

    几种tensor

    constant

    值不能改变的一种tensor

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

    不能够直接输出,需要使用session会话

    placeholder

    先占一个固定的位置,等后续再添加值的一种tensor

    tf.compat.v1.placeholder(
        dtype,
        shape=None,
        name=None
    )

    注意:

    x = tf.compat.v1.placeholder(tf.float32, shape=(1024, 1024))
    y = tf.matmul(x, x)
    
    with tf.compat.v1.Session() as sess:
      print(sess.run(y))  # ERROR: will fail because x was not fed.
    
      rand_array = np.random.rand(1024, 1024)
      print(sess.run(y, feed_dict={x: rand_array}))  # Will succeed.

    Variable

    值可以改变的一种tensor

    __init__(
        initial_value=None,
        trainable=None,
        validate_shape=True,
        caching_device=None,
        name=None,
        variable_def=None,
        dtype=None,
        import_scope=None,
        constraint=None,
        synchronization=tf.VariableSynchronization.AUTO,
        aggregation=tf.compat.v1.VariableAggregation.NONE,
        shape=None
    )

    SparseTensor

    一种稀疏tensor,类似线性代数中稀疏矩阵的概念

    spare = tf.SparseTensor(indices=[[0, 0], [1, 2]], values=[1, 2], dense_shape=[3, 4])
    with tf.Session() as sess:
        print(sess.run(tf.sparse_tensor_to_dense(spare)))

    运行结果:

    [[1 0 0 0]
     [0 0 2 0]
     [0 0 0 0]]

    张量表示法

  • 相关阅读:
    博客推荐
    oracle11g dataguard 安装手册(转)
    Linux文件系统介绍(转)
    降低磁盘IO使Oracle性能优化(转)
    关于AWR报告命中率指标的解释(转)
    oracle 锁的介绍 (转)
    oracle undo redo 解析
    oracle sqlplus 连接不正常
    Oracle技术嘉年华
    断线的回忆
  • 原文地址:https://www.cnblogs.com/SCCQ/p/12327909.html
Copyright © 2011-2022 走看看