Skip to content

Instantly share code, notes, and snippets.


cs95 Coldsp33d

  • Mountain View, CA
View GitHub Profile
from sklearn.preprocessing import OneHotEncoder
class SelectiveHandlerOHE(OneHotEncoder):
def __init__(self, *args, raise_error_cols=[], **kwargs):
kwargs['handle_unknown'] = 'ignore' # change the default
self.raise_error_cols = raise_error_cols.copy()
super().__init__(*args, **kwargs)
def check_cols(self, X):
if self.raise_error_cols and any(
import perfplot
import pandas as pd
import re
p1 = re.compile(r'\D')
p2 = re.compile(r'\d+')
def eumiro(df):
return df.assign(
result=df['result'].map(lambda x: x.lstrip('+-').rstrip('aAbBcC')))
import perfplot
import pandas as pd
import numpy as np
def brenbarn(df):
return df.assign( + " is " +
def danielvelkov(df):
return df.assign(baz=df.apply(
lambda x:'%s is %s' % (x['bar'],x['foo']),axis=1))
Coldsp33d /
Last active Oct 21, 2021
Comparing iteration and vectorisation with a simple example
import perfplot
import pandas as pd
def vec(df):
return df['A'] + df['B']
def vec_numpy(df):
return df['A'].to_numpy() + df['B'].to_numpy()
def list_comp(df):
Coldsp33d /
Last active Dec 5, 2020
Concatenate 2 (or more) lists - Benchmarking
from itertools import chain
import perfplot
import numpy
def add(L):
x, y = L
return x.copy() + y
def chain_(L):
x, y = L

This is a typing test and I'm trying to see how fast I can type. I'm trying to practice my coding skills... well, my typing skills by seeing how fast I can translate my thoughts into words on a computer. The problem with my typing style right now is that I type with my forefingers without utilizing many of my other fingers. Sometimes the occassional index finger, othertimes the ring finger. The thumb seems a reliable finger for manning the space bar so I don't disturb him much.

There is a lack of coordination between the other fingers, but my forefingers seem to be busom buddies, having no trouble whatsoever falling over each other on the keyboard to do my bidding. Sometimes, my fingers try to get cute by getting into positions they've never been in before, this inadvertently ends up costing me dearly because I make mistakes and have to backtrack to fix them. Sometimes my hands will flourish after typing a sentence, for no real reason at all — these are wasteful actions and end up reducing my wpm rate.



I was wondering if it is a good approach to define a one-line method for the sake of making the whole program more readable?

If you're assigning a function to a shorter name, yes.

short_name = module.submodule.xtrelemly_long_name_here

Now every call to module.submodule.xtrelemly_long_name_here can be substituted with short_name, for readability.

However, defining one line functions can be done like this:

"""Convolutional Neural Network with the MNIST dataset using Tensorflow."""
import numpy as np
import tensorflow as tf
def cnn_model_fn(features, labels, mode):
"""Train a CNN model on the MNIST dataset.
import numpy as np
import time
from enum import Enum
from typing import List, Iterator, Sequence, Tuple
NEIGHBOURS = [(i, j) for i in range(-1, 2) for j in range(-1, 2) if i or j]
class State(Enum):
Coldsp33d / pprint.c
Last active Jul 2, 2016
Pretty print in NumPy format, any 1D or 2D C matrix (as long as it is stored in 1D form) by specifying dimensions.
View pprint.c
#include <stdio.h>
typedef float fpoint_t;
void print(fpoint_t* m, int row_size, int col_size)
int i, j;
printf(" array([");