Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 B: | |
| def __init__(self): | |
| self.data = [] | |
| def update(self, row): | |
| for r in row: | |
| self.data.append(r) | |
| def finalize(self): | |
| return np.reshape(self.data, newshape=(len(self.data)/5, 5)) | |
| ax = B() |
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 | |
| class EpsGreedy() | |
| def __init__(self, number_of_bandits, epsilon, start_greedy= True): | |
| self.count = np.zeros(number_of_bandits) | |
| self.scores = np.array([int(!start_greedy)] * number of bandits) | |
| self.epsilon = epsilon | |
| self.bandit_count = number_of_bandits | |
| def select_arm(): | |
| choice = np.random.binomial(1,self.epsilon): | |
| if choice = 1: #EXPLORE |
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 math | |
| import random | |
| def categorical_draw(probs): | |
| ''' | |
| if | |
| P(A) = .5 | |
| P(B) = .2 | |
| P(C) = .3 |
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 math | |
| import random | |
| def categorical_draw(probs): | |
| ''' | |
| if | |
| P(A) = .5 | |
| P(B) = .2 | |
| P(C) = .3 |
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
| my_dict = dict({ | |
| 1 : "", | |
| 2 : "", | |
| 3 : "oyy", | |
| "oyy" : "", | |
| 1990 : 's kid', | |
| 2000 : "a", | |
| 2014 : "b", | |
| 2015 : "c", | |
| "foo" : "bar", |
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 info(dict): | |
| def add_item(self, item_name, question, type = None): | |
| answer = raw_input(question) | |
| if type is not None: | |
| answer = type(answer) | |
| self[item_name] = answer | |
| a = info() | |
| a.add_item("name", "What is your name? ") | |
| a.add_item("quest", "What is your quest? ") |
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 discrete_stretch(array, size): | |
| """ Expands 2d array by some factor. | |
| For example the following array is expanded by a factor of 3 | |
| [ 1 2 ] | |
| [ 3 4 ] | |
| [ 1 1 1 2 2 2] | |
| [ 1 1 1 2 2 2] | |
| [ 1 1 1 2 2 2] |
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
| from scipy.spatial.distance import euclidean | |
| points = [ | |
| [1,3], | |
| [2,4], | |
| [3,3], | |
| [4,5], | |
| [3,7], | |
| [5,1], | |
| [5,3], |
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
| # | |
| # Solution to a question posed in https://www.reddit.com/r/learnpython/comments/72ll3i/list_comprehension_help/ | |
| # | |
| # def gen_function_that_can_be_one_lined(my_list): | |
| # for i, x in enumerate(my_list): | |
| # for y in x: | |
| # yield ( i, y) | |
| # | |
| #List |
OlderNewer