Articles

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
Advertisements

Articles

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

Articles

Parallelize using xargs

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

According to this answer on StackOverflow: http://unix.stackexchange.com/questions/24954/when-is-xargs-needed/24979#24979 , 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).

Articles

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Ă !

Articles

Solve weighted least squares with NumPy

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

As posted on StackOverflow: http://stackoverflow.com/questions/27128688/how-to-use-least-squares-with-weight-matrix-in-python

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]

Articles

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:

wget http://heanet.dl.sourceforge.net/project/boost/boost/1.55.0/boost_1_55_0.tar.bz2
tar xz boost_1_55_0.tar.bz2
cd boost_1_55_0
mkdir ../boost
./bootstrap.sh --prefix=../boost
./b2 install

Articles

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")
tfile.cd()
for h in tfile.GetListOfKeys():
    h = h.ReadObj()
    print h.ClassName(), h.GetName()