In [2]:
from __future__ import print_function
import tensorflow as tf
import numpy as np
In [2]:
from datetime import date
date.today()
Out[2]:
In [3]:
author = "kyubyong. https://github.com/Kyubyong/tensorflow-exercises"
In [4]:
tf.__version__
Out[4]:
In [5]:
np.__version__
Out[5]:
In [3]:
sess = tf.InteractiveSession()
NOTE on notation
Q1. Compute the cumulative sum of X along the second axis.
In [7]:
_X = np.array([[1,2,3], [4,5,6]])
X = tf.convert_to_tensor(_X)
Q2. Compute the cumulative product of X along the second axis.
In [8]:
_X = np.array([[1,2,3], [4,5,6]])
X = tf.convert_to_tensor(_X)
Q3. Compute the sum along the first two elements and the last two elements of X separately.
In [9]:
_X = np.array(
[[1,2,3,4],
[-1,-2,-3,-4],
[-10,-20,-30,-40],
[10,20,30,40]])
X = tf.convert_to_tensor(_X)
Q4. Compute the product along the first two elements and the last two elements of X separately.
In [10]:
_X = np.array(
[[1,2,3,4],
[1,1/2,1/3,1/4],
[1,2,3,4],
[-1,-1,-1,-1]])
X = tf.convert_to_tensor(_X)
Q5. Compute the minimum along the first two elements and the last two elements of X separately.
In [11]:
_X = np.array(
[[1,4,5,7],
[2,3,6,8],
[1,2,3,4],
[-1,-2,-3,-4]])
X = tf.convert_to_tensor(_X)
Q6. Compute the maximum along the first two elements and the last two elements of X separately.
In [12]:
_X = np.array(
[[1,4,5,7],
[2,3,6,8],
[1,2,3,4],
[-1,-2,-3,-4]])
X = tf.convert_to_tensor(_X)
Q7. Compute the mean along the first two elements and the last two elements of X separately.
In [13]:
_X = np.array(
[[1,2,3,4],
[5,6,7,8],
[-1,-2,-3,-4],
[-5,-6,-7,-8]])
X = tf.convert_to_tensor(_X)
Q8. Compute the sum along the second and fourth and the first and third elements of X separately in the order.
In [14]:
_X = np.array(
[[1,2,3,4],
[-1,-2,-3,-4],
[-10,-20,-30,-40],
[10,20,30,40]])
X = tf.convert_to_tensor(_X)
Q9. Get the indices of maximum and minimum values of X along the second axis.
In [15]:
_X = np.random.permutation(10).reshape((2, 5))
print("_X =", _X)
X = tf.convert_to_tensor(_X)
Q10. Find the unique elements of x that are not present in y.
In [16]:
_x = np.array([0, 1, 2, 5, 0])
_y = np.array([0, 1, 4])
x = tf.convert_to_tensor(_x)
y = tf.convert_to_tensor(_y)
Q11. Return the elements of X, if X < 4, otherwise X*10.
In [17]:
_X = np.arange(1, 10).reshape(3, 3)
X = tf.convert_to_tensor(_X)
Q12. Get unique elements and their indices from x.
In [18]:
_x = np.array([1, 2, 6, 4, 2, 3, 2])
x = tf.convert_to_tensor(_x)
Q13. Compute the edit distance between hypothesis and truth.
In [19]:
# Check the documentation on tf.SparseTensor if you are not
# comfortable with sparse tensor.
hypothesis = tf.SparseTensor(
[[0, 0],[0, 1],[0, 2],[0, 4]],
["a", "b", "c", "a"],
(1, 5))
# Note that this is equivalent to the dense tensor.
# [["a", "b", "c", 0, "a"]]
truth = tf.SparseTensor(
[[0, 0],[0, 2],[0, 4]],
["a", "c", "b"],
(1, 6))
# This is equivalent to the dense tensor.
# [["a", 0, "c", 0, "b", 0]]
In [ ]: