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
| df = '~/path/to/some/text/file.csv' | |
| df1 = 'path/to/some/text/file.gz' | |
| import zlib | |
| import gzip | |
| with open(df, 'r', encoding='utf-8') as fh: | |
| tx = fh.read() | |
| # compress a text file |
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 datetime import datetime as DT | |
| #------------------ epoch time -----------------# | |
| >>> import time | |
| >>> time.time() | |
| 1411060580.205373 |
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
| >>> from scipy import misc as MSC | |
| >>> import os | |
| >>> df = os.path.expanduser("~/any-image.png") | |
| >>> # now read the image in as a multi-dimensional array (matrix) | |
| >>> # 'imread' is a wrapper over a PIL method | |
| >>> mg1 = MSC.imread(df) | |
| >>> mg1.shape |
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 time | |
| import numpy as NP | |
| from redis import StrictRedis as redis | |
| # a 2D array to serialize | |
| A = 10 * NP.random.randn(10000).reshape(1000, 10) | |
| # flatten the 2D NumPy array and save it as a binary string | |
| array_dtype = str(A.dtype) |
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
| ''' | |
| these 2 functions assume this sort of MLP architecture: | |
| (i) a classification problem modeled w/ softmax activation function | |
| (ii) encode the output layer w/ 1-of-N | |
| > so for raw data like this: | |
| .3, .2, .6, .1, 'class I' | |
| .6, .1, .8, .4, 'class II' | |
| .5, .2, .7, .3, 'class III' | |
| recode it for intput to a softmax MLP like so: |
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
| #Newbie programmer | |
| def factorial(x): | |
| if x == 0: | |
| return 1 | |
| else: | |
| return x * factorial(x - 1) | |
| print factorial(6) | |
| #First year programmer, studied Pascal |
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
| # let's say you have four sequences you want to print columnwise, like so: | |
| 19 59 97 44 | |
| 92 57 63 68 | |
| 66 21 69 90 | |
| 75 66 12 19 | |
| # mock some data | |
| import random as RND | |
| gen_row = lambda: [ RND.randint(10, 99) for c in range(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
| # useful eg, for recursive functions such as merge sort or binary tree building/traversal in which sometimes the fn must return one of two portions of some container (a sequence, tree node, etc.) | |
| def fnx(a): | |
| if a % 2 == 0: | |
| x = 45 | |
| y = None | |
| else: | |
| x = None | |
| y = 3 | |
| return (x or y) + 2 |