10 KiB
10 KiB
In [ ]:
s = 'hello'
s[0] = 'a'In [ ]:
import numpy as np
def subtract_smooth(x, y):
y_new = y - median_filter(x, y, 2.5)
return y_new
def median_filter(x, y, width):
y_new = np.zeros(y.shape)
for i in range(len(x)):
y_new[i] = np.median(y[np.abs(x - x[i]) < width * 0.5])
return y_newIn [ ]:
subtract_smooth(np.array([1,2,3,4,5]),np.array([4,5,6,8]))In [ ]:
subtract_smooth(np.array([1,2,3,4,5]),np.array([4,5,6,8]))In [ ]:
%debugIn [ ]:
s = 'hello'In [ ]:
s[1] = 'a'In [ ]:
try:
s[1] = 'a'
except:
print("Can't set s[1]")In [ ]:
try:
s[1] = 'a'
except TypeError:
print("Can't set s[1]; TypeError")In [ ]:
try:
s[1] = 'a'
except ValueError:
print("Can't set s[1]")In [ ]:
raise ValueError("But writing good, descriptive error messages is.")In [ ]:
# THIS IS HOW *NOT* TO DO IT!
try:
with open("/etc/passwd", "a") as f:
pass
except IOError:
# don't do this anyway: Catch and raise something else
# And in particular don't claim more than you know.
raise Exception("/etc/passwd does not exist")