Skip to content

Instantly share code, notes, and snippets.

@dlouapre
dlouapre / numpy-04_fft.py
Created December 5, 2012 15:59
Numpy FFT
# -*- coding: utf-8 -*-
from numpy import *
from numpy.random import *
from numpy.fft import *
from pylab import *
N = 2**9 # FFT works better with signals whose length is power of 2
T = 10 # Length of time interval
t = linspace(0,T,N)
@dlouapre
dlouapre / numpy-03_random
Created December 4, 2012 19:50
Numpy Random
# -*- coding: utf-8 -*-
from numpy import *
from numpy.random import *
# Discrete distributions
binomial(n=100, p=0.3, size = 5) # e.g. array([24, 39, 27, 33, 32])
poisson (lam=30, size = 5) # Poisson of average lambda = 30
# Continuous
normal(loc=10, scale=3, size=5)
@dlouapre
dlouapre / numpy-02_linalg
Created December 4, 2012 19:47
Numpy Linear Algebra
# -*- coding: utf-8 -*-
from numpy import *
from numpy.linalg import *
# Create matrices
a_list = [[0,1,2],[4,9,2],[-3,1,3]]
a_array = array(a_list)
A = matrix(a_array)
B = mat('1 2 3') # Line vector
B = mat('1;2;3') # Column vector
@dlouapre
dlouapre / excel_read.py
Created December 3, 2012 21:07
Read excel file in Python
# -*- coding: utf-8 -*-
import xlrd
# Open the file
wb = xlrd.open_workbook('test.xlsx')
# Get the list of the sheets name
sheet_list = wb.sheet_names()
print sheet_list
@dlouapre
dlouapre / numpy-01_basics.py
Created December 3, 2012 14:15
Numpy Basics
# -*- coding: utf-8 -*-
from numpy import *
''' ----------------------------------------------------- '''
''' Differences between operations on list and on ndarray '''
''' ----------------------------------------------------- '''
# Lists
x = [1,2,3]
y = [4,5,6]