How to print the value of a Tensor object in TensorFlow?

前端 未结 21 1871
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 07:44

I have been using the introductory example of matrix multiplication in TensorFlow.

matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
produ         


        
21条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 07:50

    Based on the answers above, with your particular code snippet you can print the product like this:

    import tensorflow as tf
    #Initialize the session
    sess = tf.InteractiveSession()
    
    matrix1 = tf.constant([[3., 3.]])
    matrix2 = tf.constant([[2.],[2.]])
    product = tf.matmul(matrix1, matrix2)
    
    #print the product
    print(product.eval())
    
    #close the session to release resources
    sess.close()
    

提交回复
热议问题