This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import tensorflow as tf | |
| print 'tf_version: ', tf.__version__ # it is 1.4.0 right now | |
| np.set_printoptions(linewidth=150, precision=3, suppress=True) | |
| M = 10 | |
| d = 2 | |
| # samples | |
| X = tf.constant(np.random.randn(M, d), 'float32') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Iterator(object): | |
| """ | |
| Iterator for list of tensors whose first dimension match. | |
| """ | |
| def __init__(self, tensors, batch_size, allow_smaller=True, shuffle=True): | |
| self.tensors = tensors | |
| self.batch_size = batch_size | |
| self.allow_smaller = allow_smaller | |
| self.shuffle = shuffle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def pairwise_dist (A, B): | |
| """ | |
| Computes pairwise distances between each elements of A and each elements of B. | |
| Args: | |
| A, [m,d] matrix | |
| B, [n,d] matrix | |
| Returns: | |
| D, [m,n] matrix of pairwise distances |