test01.py 748 B

123456789101112131415161718192021222324252627282930313233343536
  1. import tensorflow as tf
  2. import numpy as np
  3. import os
  4. os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
  5. def foo01():
  6. x = np.array([[1, 1, 1], [1, -8, 1], [1, 1, 1]])
  7. w = tf.Variable(initial_value=x)
  8. sess = tf.Session()
  9. sess.run(tf.global_variables_initializer())
  10. print(sess.run(w))
  11. def foo02():
  12. x = tf.Variable(3)
  13. y = tf.Variable(5)
  14. z = tf.add(x, y)
  15. sess = tf.Session()
  16. sess.run(tf.global_variables_initializer())
  17. print(sess.run(z))
  18. def foo03():
  19. a = tf.Variable(tf.ones([3, 2]))
  20. b = tf.Variable(tf.ones([2, 3]))
  21. product = tf.matmul(5.0 * a, 4.0 * b)
  22. sess = tf.Session()
  23. sess.run(tf.global_variables_initializer())
  24. print(sess.run(product))
  25. print(tf.__path__)
  26. foo01()
  27. foo02()
  28. foo03()