TensorFlow学习笔记(15)tenforflow打印tensor的值

github代码

  import tensorflow as tf                                                                                                    
  import numpy as np                                                                                                         
                                                                                                                             
  with tf.Session() as sess:                                                                                                 
      x = tf.constant([[1, 2, 4], [8, 16, 32]]) # 2x2 matrix                                                                 
                                                                                                                             
      #  Tensor("Const:0", shape=(2, 3), dtype=int32)                                                                        
      print(x)                                                                                                               
                                                                                                                             
      # 方法1                                                                                                                
      #  [[ 1  2  4]                                                                                                         
      #   [ 8 16 32]]                                                                                                        
      print(x.eval())                                                                                                        
                                                                                                                             
      # 方法2                                                                                                                
      #  [[ 1  2  4]                                                                                                         
      #   [ 8 16 32]]                                                                                                        
      print(sess.run(x))     
    原文作者:谢昆明
    原文地址: https://www.jianshu.com/p/d220dc0046a5
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞