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

来源:互联网 发布:java 蓝牙通信协议 编辑:程序博客网 时间:2024/05/21 08:44
# -*- 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))
原创粉丝点击