{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import tensorflow as tf" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[5.0, 2.0]\n" ] } ], "source": [ "# Fetch\n", "a = tf.constant(1.0)\n", "b = tf.constant(2.0)\n", "c = tf.constant(3.0)\n", "multiply = tf.multiply(a, b)\n", "add = tf.add(matmul, c)\n", "\n", "# Fetch可以运行多个 Op\n", "with tf.Session() as sess:\n", " print(sess.run([add, multiply]))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ 2.]\n" ] } ], "source": [ "# Feed\n", "ph1 = tf.placeholder(tf.float32)\n", "ph2 = tf.placeholder(tf.float32)\n", "m = tf.multiply(ph1, ph2)\n", "\n", "# 在真正执行的时候,再将数据以字典的形式传入\n", "with tf.Session() as sess:\n", " print(sess.run(m, feed_dict={ph1: [1.0], ph2: [2.0]}))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.3" } }, "nbformat": 4, "nbformat_minor": 2 }