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
| grep -n "pattern" file.csv | awk -F ":" '{print $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
| cat input.txt | awk '{ print length, $0 }' | sort -n -s | cut -d" " -f2- > input-sorted.txt | |
| # reverse order | |
| cat input.txt | awk '{ print length, $0 }' | sort -n -r | cut -d" " -f2- > input-sorted-rev.txt |
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
| data[data.columns[::-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
| def pca(X, npc): | |
| n_samples, n_features = X.shape | |
| Xmean = np.mean(X, axis=0) | |
| U, s, Vt = scipy.sparse.linalg.svds(X - Xmean, k=npc) | |
| order = np.argsort(-s) # sort s in descending order | |
| # svds returns U, s, Vt sorder in ascending order. We want descending | |
| s = s[order] | |
| W = Vt[order,:] |
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 csv | |
| import os | |
| import pprint | |
| import datetime | |
| #splits file returns the files splitted and the number of files(current_piece) | |
| import csv | |
| def splits(filehandler, delimiter=',', row_limit=100000, | |
| output_name_template='output_%s.csv', output_path='.', keep_headers=True): | |
| """ |
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 matplotlib.pyplot as plt | |
| from scipy.sparse import coo_matrix | |
| def plot_coo_matrix(m): | |
| if not isinstance(m, coo_matrix): | |
| m = coo_matrix(m) | |
| fig = plt.figure() | |
| ax = fig.add_subplot(111, axisbg='black') | |
| ax.plot(m.col, m.row, 's', color='white', ms=1) | |
| ax.set_xlim(0, m.shape[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
| find . -depth -name '*(*' | while IFS= read -r f ; do mv -i "$f" "$(dirname "$f")/$(basename "$f"|tr '(' _)" ; done | |
| find . -depth -name '*)*' | while IFS= read -r f ; do mv -i "$f" "$(dirname "$f")/$(basename "$f"|tr ')' _)" ; done | |
| find . -depth -name '* *' | while IFS= read -r f ; do mv -i "$f" "$(dirname "$f")/$(basename "$f"|tr ' ' _)" ; done |