Last active
June 13, 2020 00:38
-
-
Save eldon/c083c0cb4e1acb079f4aeee148eca2f9 to your computer and use it in GitHub Desktop.
spicy_python_oneliners
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
| # create a one-hot embedding for labels from (labels, examples) pairs | |
| examples_labels = [[np.insert(np.zeros(4, dtype=np.int64), i, 1)] * e.shape[0] for i, e in enumerate(examples)] | |
| # filter a list of words for words with numbers in them | |
| df_word[np.vectorize(lambda x: any(map(str.isnumeric, x)))(df_word.word)] | |
| # What's the index of the first nonconsecutive integer stored in a list of strings? | |
| unique_numbers = df_numstrs[np.vectorize(lambda x: x.isnumeric())(df_numstrs.word.astype(int, errors='ignore'))].astype(int).drop_duplicates('word').sort_values('word')['word'].values | |
| np.argmax(np.ediff1d(unique_numbers) > 1) | |
| # Separate named lists of pairwise coordinates into named lists of unpaired coordinates | |
| go_data[plot['name']] = {k: list(zip(*plot['streams'][k])) for k in plot['streams']} | |
| # Make a list of Error classes from a lookup table, then instantiate those errors with data from inside that table | |
| result_divs = [ERROR_KEYS[error['error_id_str']](error['epoch']).render({'type': 'error-msg', 'index': i}) for i, error in enumerate(errors)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment