# import libraries
import tensorflow as tf
import pandas as pd
import sys
print('Python version ' + sys.version)
print('Tensorflow version ' + tf.VERSION)
print('Pandas version ' + pd.__version__)
Python version 3.5.1 |Anaconda custom (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)] Tensorflow version 0.12.0-rc0 Pandas version 0.19.0
df = pd.DataFrame({'a':[2,4,6,8],
'b':[2,2,2,2]})
df
a | b | |
---|---|---|
0 | 2 | 2 |
1 | 4 | 2 |
2 | 6 | 2 |
3 | 8 | 2 |
Placeholders allow you to pass in data at run time.
# placeholders are used to feed data to your graph
a = tf.placeholder(tf.int32, name = "var_a")
b = tf.placeholder(tf.int32, name = "var_b")
# multiply a * b
c = tf.mul(a, b)
A *Session* object encapsulates the environment in which Operation objects are executed, and Tensor objects are evaluated.
*Note:* We cannot use *df.to_dict('list')* because the *key* cannot be in between quotes.
# Run your graph inside a session
with tf.Session() as sess:
# This is how you feed data in
print(sess.run(c, feed_dict = {a:df['a'].tolist(), b:df['b'].tolist()}))
[ 4 8 12 16]
This tutorial was created by HEDARO