Tensorflow学习笔记(2)-基本运算

版权声明:博客仅供参考,有什么意见,请在下方留言,转载时请附上链接,谢谢! https://blog.csdn.net/u010105243/article/details/76556885
# -*- coding: utf-8 -*-
# @Time    : 17-8-1 下午8:02
# @Author  : 未来战士biubiu!!
# @FileName: 2-basic operation.py
# @Software: PyCharm Community Edition
# @Blog    :http://blog.csdn.net/u010105243/article/

import tensorflow as tf
#第一种计算方式
# a = tf.constant(2)
# b = tf.constant(3)
# with tf.Session() as sess:
#     print("a:%i" % sess.run(a), "b:%i" % sess.run(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}))

#矩阵运算
mat1 = tf.constant([[2., 3.]])
mat2 = tf.constant([[2.], [2.]])
product = tf.matmul(mat1, mat2)
with tf.Session() as sess:
    print(sess.run(product))

猜你喜欢

转载自blog.csdn.net/u010105243/article/details/76556885