zoukankan      html  css  js  c++  java
  • TensorFlow基础笔记(0) tensorflow的基本数据类型操作

    import numpy as np
    import tensorflow as tf
    
    #build a graph
    print("build a graph")
    #生产变量tensor
    a=tf.constant([[1,2],[3,4]])
    b=tf.constant([[1,1],[0,1]])
    #获取tensor的数据类型和张量维度
    print("a.dtype",a.dtype)
    print(a.get_shape())
    print("type of a:",type(a))
    
    #基本的数据运算
    c=tf.matmul(a,b)
    d=tf.subtract(a,b)
    e=tf.add(a,b)
    print("a:",a)
    print("b:",b)
    #construct a 'Session' to excute the graph
    sess=tf.Session()
    # Execute the graph and store the value that `c` represents in `result`.
    print("excuted in Session")
    result_a=sess.run(a)
    result_a2=a.eval(session=sess)
    print("result_a:
    ",result_a)
    print("result_a2:
    ",result_a2)
    
    result_b=sess.run(b)
    print("result_b:
    ",result_b)
    
    result_c=sess.run(c)
    print("result_c:
    ",result_c)
    
    result_d=sess.run(d)
    print("result_d:
    ",result_d)
    
    result_e=sess.run(e)
    print("result_e:
    ",result_e)

    #Tensors常量值函数
    tf.zeros(shape, dtype=tf.float32, name=None)
    tf.zeros_like(tensor, dtype=None, name=None)
    tf.ones(shape, dtype=tf.float32, name=None)
    tf.ones_like(tensor, dtype=None, name=None)
    tf.fill(dims, value, name=None)
    tf.constant(value, dtype=None, shape=None, name='Const')

  • 相关阅读:
    第十八周个人作业
    十六周个人作业
    个人作业
    第十四周总结
    第十三周周末总结
    排球计分程序说明书
    我和计算机
    排球比赛记分员
    逻辑思维怎样成为一个高手
    用户故事排球教练助手
  • 原文地址:https://www.cnblogs.com/adong7639/p/8608696.html
Copyright © 2011-2022 走看看