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 | |
| from torchvision.datasets import MNIST, SVHN | |
| from torchvision import transforms | |
| import torch | |
| from torch.utils.data import DataLoader | |
| def normalize(data_tensor): | |
| '''re-scale image values to [-1, 1]''' | |
| return (data_tensor / 255.) * 2. - 1. |
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
| '''add ta and tb 5 times, and then multiply them 5 times''' | |
| import tensorflow as tf | |
| ta = tf.ones([3], dtype=tf.float32) | |
| tb = tf.zeros([3], dtype=tf.float32) | |
| global_step = tf.Variable(0, trainable=False) | |
| add_global_step = global_step.assign_add(1) | |
| add_step = 5 | |
| total_step = 10 |
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 tensorflow as tf | |
| # get variables by name | |
| def _param_by_name(name): | |
| all_vars = tf.trainable_variables() | |
| filtered_vars = [] | |
| for v in all_vars: | |
| if name in v.name: | |
| filtered_vars.append(v) |
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 tensorflow as tf | |
| num_units = 2 | |
| batch_size = 3 | |
| n_dim = 4 | |
| seq_len = 5 | |
| sess = tf.Session() | |
| image_embeddings = tf.zeros([batch_size, n_dim]) | |
| seq_embeddings = tf.zeros([batch_size, seq_len, n_dim]) |
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 tensorflow as tf | |
| import numpy as np | |
| T = 2 | |
| d = 3 | |
| x = np.arange(T*d).reshape((T,d)) | |
| y = x+1 | |
| tx = tf.constant(x) | |
| ty = tf.constant(y) |
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
| /** | |
| * Definition for binary tree | |
| * struct TreeNode { | |
| * int val; | |
| * TreeNode *left; | |
| * TreeNode *right; | |
| * TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
| * }; | |
| */ | |
| class Solution { |
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 Solution { | |
| public: | |
| // if a==b, return 0 | |
| // else return 1 | |
| int diffDistance(char a, char b){ | |
| if(a==b) | |
| return 0; | |
| else | |
| return 1; | |
| } |
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
| #include <iostream> | |
| #include <assert.h> | |
| using namespace std; | |
| /* function: find the length of longest increasing subsequences of input array | |
| * arr - input integer array | |
| * n - length of arr | |
| */ | |
| int lis(const int *arr, int n) |
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
| #include <iostream> | |
| using namespace std; | |
| int Fabonacci(int n) | |
| { | |
| if(n>=0 && n<2) | |
| return 1; | |
| // create a new array for memoization | |
| int *f = new int[n+1]; |