您的位置:首页 > 其它

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

2017-08-01 20:20 162 查看
# -*- 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))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: