a = 34
b = 34
print(a + b)
a + b
c = 100
c + b
q = []
def length(q):
"""Returns number of waiting customers"""
return len(q)
def show(q):
"""SHOW queue: print list of waiting customers. Customer waiting longest
are shown at the end of the list."""
print("Customers waiting are:")
print(q)
def add(q, name):
"""Customer with name 'name' joining the queue"""
q.append(name)
def next_ (q):
"""Returns name of next customer to serve, removes customer from queue"""
return q.pop(0)
# main programme starts here
add(q, "Hawke")
add(q, "Fangohr")
show(q)
print("Length of queue is {}".format(length(q)))
print("Next customer is {}".format(next_(q)))
#print("Next customer is {}".format(next_(q)))
print("Length of queue is {}".format(length(q)))
import math
def mexhat(t, sigma=1):
"""Computes Mexican hat shape, see
http://en.wikipedia.org/wiki/Mexican_hat_wavelet for
equation (13 Dec 2011)"""
c = 2. / math.sqrt(3 * sigma) * math.pi ** 0.25
return c * (1 - t ** 2 / sigma ** 2) * \
math.exp(-t ** 2 / (2 * sigma ** 2))
The mexhat function implements the equation $$ f(t) = c\left(1 - \frac{t^2}{\sigma^2}\right) \exp\left(-\frac{t^2}{2\sigma^2}\right) $$
import numpy as np
def create_xs_ys(tmin, tmax, N):
xs = np.linspace(tmin, tmax, N)
ys = [mexhat(x) for x in xs]
return xs, ys
xs, ys = create_xs_ys(-5, 5, 1000)
%matplotlib inline
import pylab
def plot(xs, ys):
pylab.plot(xs, ys)
pylab.xlabel('t')
pylab.ylabel('f(t)')
plot(xs, ys)