import tensorflow as tf


string  = tf.constant("Hello World")


with tf.Session() as sess:
    #在sess中运行op
    print(sess.run(string))

a = tf.constant(2)
b = tf.constant(3)

with tf.Session() as sess:
    print("a = 2 ,b = 3")
    print("计算a+b = %i" % sess.run(a+b))
    print("计算a*b = %i" % sess.run(a*b))

a = tf.placeholder(tf.int16)
b = tf.placeholder(tf.int16)
add = tf.add(a,b)
mul = tf.multiply(a,b)

with tf.Session() as sess:
    print("计算a+b = %i" % sess.run(add,feed_dict={a:2,b:3}))
    print("计算a*b = %i" % sess.run(mul,feed_dict={a:2,b:3}))\

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

product = tf.matmul(matrix1,matrix2)

with tf.Session() as sess:
    result = sess.run(product)
    print(result)

 

TensorFlow经典案例1:基本操作

公众号:一个有趣的机器学习社区

(大量机器学习资料分享)

相关文章:

  • 2022-12-23
  • 2017-11-24
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-28
  • 2021-09-27
  • 2021-12-28
  • 2021-10-27
  • 2022-12-23
  • 2022-02-09
  • 2021-12-16
相关资源
相似解决方案