Install python stack on Ubuntu 16.04

In howto on May 22, 2017 by theoryl Tagged:

Note to self:

# First, install pip
sudo apt install python-pip

# Upgrade pip
sudo -H pip install --upgrade pip

# Install python stack using pip
sudo -H pip install setuptools
sudo -H pip install ipython
sudo -H pip install numpy scipy
sudo -H pip install matplotlib pandas
sudo -H pip install Theano
sudo -H pip install keras


Find and replace in all the files

In howto on Nov 17, 2016 by theoryl Tagged: , ,

This simple one liner does it:

find ./ -type f -exec sed -i -e 's/apple/orange/g' {} \;

from StackOverflow


Parallelize using xargs

In howto on Sep 7, 2016 by theoryl Tagged: , , , ,

According to this answer on StackOverflow: , you can easily parallelize tasks using xargs. To quote the given example:

$ find . -type f -name '*.wav' -print0 | xargs -0 -P 3 -n 1 flac -V8

This example will encode *.wav => *.flac, using three processes at once (-P 3).


Install IPython on Ubuntu

In howto on Aug 3, 2016 by theoryl Tagged: , , , ,

IPython is a much more powerful shell than the usual Python shell. As Ubuntu and Linux Mint are already shipped with python and pip, installing IPython is trivial:

sudo pip install ipython

VoilĂ !


Solve weighted least squares with NumPy

In python on Aug 3, 2016 by theoryl Tagged: , , , ,

As posted on StackOverflow:

import numpy as np

# Solve for X in AX = B
A = np.array([[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,0,0]])
B = np.array([1,1,1,1,1])
W = np.array([1,2,3,4,5])
Aw = A * np.sqrt(W[:,np.newaxis])
Bw = B * np.sqrt(W)
X = np.linalg.lstsq(Aw, Bw)[0]


Build Boost 1.55 on Linux

In howto on Aug 2, 2016 by theoryl Tagged: , ,

Boost is a very extensive C++ library. To compile + install:

tar xz boost_1_55_0.tar.bz2
cd boost_1_55_0
mkdir ../boost
./ --prefix=../boost
./b2 install


Loop over histograms in ROOT file

In python on Jul 29, 2016 by theoryl Tagged: , ,

Looping over all histograms in a ROOT file using pyROOT

from ROOT import TFile
tfile = TFile.Open("histos.root")
for h in tfile.GetListOfKeys():
    h = h.ReadObj()
    print h.ClassName(), h.GetName()