From ef68cae1c0e2c16ff1d5529db2468a30d9182360 Mon Sep 17 00:00:00 2001 From: Jakub Fojt Date: Mon, 28 Jun 2021 11:07:52 +0200 Subject: [PATCH] Inspect npz --- .bashrc.kuba | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.bashrc.kuba b/.bashrc.kuba index b3b7cfb..7fd4b26 100755 --- a/.bashrc.kuba +++ b/.bashrc.kuba @@ -24,6 +24,32 @@ alias ls='ls --color=auto' # Define a OS X-like open command open() { command xdg-open "$@" > /dev/null 2>&1 & } +# Inspect .npz files +npz_py_str="$(cat << EOM +from sys import argv + +class Wrap: + def __init__(self, fname): + import numpy as np + n = np.load(fname, allow_pickle=True) + files = n.files + print('Contains files', files) + for f in files: + setattr(self, f, n[f]) + +d = Wrap(argv[1]) +EOM +)" + +npz_preview() { + if [ $# -lt 1 ]; then + echo "Please specify file to open as argument" + return + fi + + python -ic "$npz_py_str" "$1" +} + # Source git prompt source_existing ~/scripts/git-prompt.sh source_existing ~/.bash_prompt.kuba