from numpy import *
zeros((4,7))
zeros((4))
ones(8)
eye(5)
random.rand(4,5)
a = linspace(10,20,11)
a
type(a)
a.dtype
d = ones(5,dtype=int)
d
a = random.randint(0,10,(7,4))
a
a[1]
a[5,3]
a[5,3]=19
a
#random.seed(46473)
random.randint(0,10,(7,4))
a
a[::2,:]
a[::2,:-1]
a[::2,:-1] = 0
a
nr = 40
nc = 40
mask = zeros((nr,nc,3),dtype=uint8)
mask[:10,:10,:] = 1
import matplotlib.pyplot as plt
%matplotlib inline
plt.imshow(255*mask,interpolation='none');
a = ones((4,5))
a
5*a
nr = 40
nc = 40
mask = zeros((nr,nc,3),dtype=uint8)
mask[::2,::2,:] = 1
mask[1::2,1::2,:] = 1
plt.imshow(255*mask,interpolation='none');
#a = zeros((nr,nc,3),dtype=uint8)
v = zeros_like(mask)
# let's make some stripes
v[:,:10,] = [150,0,150]
v[:,12:15,:] = [255,0,0]
h = v.transpose(1,0,2)
plt.imshow(mask*v + (1-mask)*h,interpolation='none');
from numpy import *
#matplotlib inline
from scipy.misc import imsave, imshow
import os
r = 2.
h = 500
w = 499
x = linspace(-r, r,w)
y = linspace( r,-r,h)
X,Y = meshgrid(x,y)
Z = X + 1.0j*Y
def newton(z):
return 2.*z/3. + 1./(3.*z**2)
root1 = 1.
root2 = -.5 + 1.j*sqrt(3.)/2.
root3 = -.5 - 1.j*sqrt(3.)/2.
a = zeros((h,w,3))#,dtype=uint8)
red = a[:,:,0]
green = a[:,:,1]
blue = a[:,:,2]
for i in range(10):
Z = newton(Z)
red [ abs(Z-root1)<.1 ] += 1
green[ abs(Z-root2)<.1 ] += 1
blue [ abs(Z-root3)<.1 ] += 1
#a *= 10
imsave('complex_newton.py.png',a)
#imshow(a)
os.system('eog complex_newton.py.png&')
from scipy.io import wavfile
w = wavfile.read('black_holes_merge.wav')
len(w)
w
samplerate,data = wavfile.read('black_holes_merge.wav')
samplerate
type(data)
data.shape
plt.plot(data[70000:120000,0],'r',alpha=0.5,lw=3)
plt.plot(data[70000:120000,1],'b',alpha=0.5);
x = linspace(0,10,500)
plt.plot(x,sin(x));