Skip to content

Instantly share code, notes, and snippets.

View ig248's full-sized avatar

Igor Gotlibovych ig248

View GitHub Profile
@ig248
ig248 / reshape_for_kernel_fitting.py
Created June 12, 2020 11:12
Quick and dirty AR/kernel/convolutions models using `stride_tricks`
def reshape_for_fitting(arr, kernel_half_width=0, kernel_lag=0, pad_kwargs=None):
"""Reshape 1D array into a shape suitable for easy convolution/AR model fitting."""
assert len(arr.shape) == 1, "Array must be 1D"
n = len(arr)
pad_kwargs = pad_kwargs or {}
pad_left = max(kernel_half_width - kernel_lag, 0)
pad_right = max(kernel_half_width + kernel_lag, 0)
arr_padded = np.pad(arr, [(pad_left, pad_right)], **pad_kwargs)
return stride_tricks.as_strided(
arr_padded,
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
kubectl get pods --sort-by=.status.conditions[0].lastTransitionTime
def cartesian(arrays):
"""
Generate a cartesian product of input arrays.
Parameters
----------
arrays : list of array-like
1-D arrays to form the cartesian product of.
out : ndarray
Array to place the cartesian product in.
def repeat(df, count_column):
expanded_df = df.loc[
df.index.repeat(repeats=df[count_column])
].reset_index(drop=True)
expanded_df[count_column] = 1
return expanded_df
@ig248
ig248 / get_available_gpus.py
Created November 1, 2017 23:45 — forked from jovianlin/get_available_gpus.py
Get List of Devices in TensorFlow
from tensorflow.python.client import device_lib
def get_available_gpus():
local_device_protos = device_lib.list_local_devices()
return [x.name for x in local_device_protos if x.device_type == 'GPU']
get_available_gpus()
@ig248
ig248 / powerline_prompt.lua
Last active February 26, 2018 17:56
Customized cmder prompt (Windows) - requires custom fonts, see https://amreldib.com/blog/CustomizeWindowsCmderPrompt/ and https://github.com/powerline/fonts
-- Code based on https://github.com/cmderdev/cmder/issues/1056
-- with modifications to make it work with conda/virtual envs (https://github.com/cmderdev/cmder/issues/1056#issuecomment-237403714)
local clink_path_lua_file = clink.get_env('CMDER_ROOT')..'\\vendor\\clink-completions\\modules\\path.lua'
dofile(clink_path_lua_file)
---
-- Find out current conda/virtual envs
-- @return {false|conda/virtual env name}
---