Skip to content

Instantly share code, notes, and snippets.

def pca(X):
"""
Features are in columns
"""
# Data matrix X, assumes 0-centered
n, m = X.shape
assert np.allclose(X.mean(axis=0), np.zeros(m))
# Compute covariance matrix
fig = figure(1);
set(gcf,'units','points','position',[0,0,1200,500])
@terbed
terbed / install.sh
Last active September 3, 2018 12:16
Install libarmadillo in Qt project #linux #Qt
sudo apt-get install liblapack-dev
sudo apt-get install libblas-dev
sudo apt-get install libboost-dev
sudo apt-get install libarmadillo-dev
@terbed
terbed / .bashrc
Last active September 3, 2018 12:17
Add library path to linux bash #linux
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/pylon5/lib64
@terbed
terbed / search
Last active February 6, 2019 10:45
Search in linux terminal #linux
@terbed
terbed / terminal
Last active September 3, 2018 12:19
Linux terminal without graphical interface #linux
Ctrl+Alt+F1
@terbed
terbed / .linux
Last active September 3, 2018 12:10
Install package in conda environment #linux #anaconda
conda install pip
source activate base (or env...)
pip install [package]
@terbed
terbed / subtract_from_3c.cpp
Last active September 3, 2018 12:21
Iterate through opencv c++ matrix #cpp #opencv
// subtract IR from BGR
Vec3u tmp;
for (int i = 0; i < ir.rows; i++) {
for (int j = 0; j < ir.cols; j++) {
tmp = bgr.at<Vec3u>(i,j);
tmp[0] = tmp[0] - ir.at<ushort>(i,j);
tmp[1] = tmp[1] - ir.at<ushort>(i,j);
tmp[2] = tmp[2] - ir.at<ushort>(i,j);
bgr.at<Vec3u>(i, j) = tmp;
@terbed
terbed / exception.py
Last active September 3, 2018 12:37
Exceptions. #python
def print_object(some_object):
# Check if the object is printable...
try:
printable = str(some_object)
except TypeError:
print("unprintable object")
else:
print(printable)
@terbed
terbed / colored.py
Last active September 3, 2018 12:36
Generators #python
def colored_noise_generator(D, lamb, dt):
"""
An iterable generator function for colored noise.
:param D: Amplitude of the noise
:param lamb: Reciprocal of the characteristic time
:param dt: Time step
:return : yields the successive value
"""