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]]

    张量表示法

  • 相关阅读:
    DRF小结
    js中BOM与DOM的概念与区别
    css单位分析、颜色设置与调色板
    css中伪类与伪元素的区别
    flexbox与grid layout的区别
    grid的简单使用
    position属性的总结
    html,css
    homework
    aboutme and my goal
  • 原文地址:https://www.cnblogs.com/SCCQ/p/12327909.html
Copyright © 2011-2022 走看看