Skip to content

Instantly share code, notes, and snippets.

import sys
from types import ModuleType, FunctionType
from gc import get_referents
# Custom objects know their class.
# Function objects seem to know way too much, including modules.
# Exclude modules as well.
BLACKLIST = type, ModuleType, FunctionType
# Long running cell
import multiprocessing, time
def network_call():
for i in range(20):
print(i)
time.sleep(1)
multiprocessing.Process(target=network_call).start()
import mygene
def namespace_mapping(names, map_from=['symbol', 'alias'], map_to='symbol', species='human'):
names = pd.Series(names)
print(f"passed {len(names)} symbols")
names_stripped = names.str.strip()
if any(names_stripped != names):
import PIL.Image
from matplotlib.pyplot import imshow
def show(*Ms):
fig, axs = plt.subplots(ncols=len(Ms))
for M, ax in zip(Ms, (axs if type(axs) == list else [axs])):
M = np.atleast_2d(M)
ax.imshow(PIL.Image.fromarray((M - M.min()) * 255 / M.max()))
ax.set_xticks([0, M.shape[1]])
ax.set_yticks([0, M.shape[0]])
for side in ["right","top","bottom","left"]:
{
"cells": [
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.