In [1]:
import numpy as np
In [2]:
a = np.matrix('1,2,1;2,4,2;1,2,1')
prod = np.multiply (a, [0.0625])

u, z, v = np.linalg.svd(prod, full_matrices='true')

print 'u, z and v: '
print u.round(2)
print z.round(2)
print v.round(2)

u1 = u[:,0]
v1 = v[0,:]
v1t = v1.transpose()

root_z1 = np.sqrt(z[0])

sp_u = np.multiply(u1, [root_z1])
sp_v = np.multiply(v1t, [root_z1])

print 'Seperable Filters: '
print sp_u
print sp_v
u, z and v: 
[[-0.41  0.91  0.  ]
 [-0.82 -0.37 -0.45]
 [-0.41 -0.18  0.89]]
[ 0.38  0.    0.  ]
[[-0.41 -0.82 -0.41]
 [-0.91  0.37  0.18]
 [-0.    0.45 -0.89]]
Seperable Filters: 
[[-0.25]
 [-0.5 ]
 [-0.25]]
[[-0.25]
 [-0.5 ]
 [-0.25]]
In [3]:
a = np.matrix('-1,0,1;-2,0,2;-1,0,1')
prod = np.multiply (a, [0.125])

u, z, v = np.linalg.svd(prod, full_matrices='true')

print 'u, z and v: '
print u.round(2)
print z.round(2)
print v.round(2)

u1 = u[:,0]
v1 = v[0,:]
v1t = v1.transpose()

root_z1 = np.sqrt(z[0])

sp_u = np.multiply(u1, [root_z1])
sp_v = np.multiply(v1t, [root_z1])

print 'Seperable Filters: '
print sp_u.round(2)
print sp_v.round(2)
u, z and v: 
[[-0.41  0.91 -0.  ]
 [-0.82 -0.37 -0.45]
 [-0.41 -0.18  0.89]]
[ 0.43  0.    0.  ]
[[ 0.71  0.   -0.71]
 [ 0.71  0.    0.71]
 [ 0.    1.    0.  ]]
Seperable Filters: 
[[-0.27]
 [-0.54]
 [-0.27]]
[[ 0.47]
 [ 0.  ]
 [-0.47]]
In [4]:
a = np.matrix('1,2,3;4,5,6;7,8,9')
prod = np.multiply (a, [0.125])

u, z, v = np.linalg.svd(prod, full_matrices='true')

print 'u, z and v: '
print u.round(2)
print z.round(2)
print v.round(2)
u, z and v: 
[[-0.21  0.89  0.41]
 [-0.52  0.25 -0.82]
 [-0.83 -0.39  0.41]]
[ 2.11  0.13  0.  ]
[[-0.48 -0.57 -0.67]
 [-0.78 -0.08  0.63]
 [-0.41  0.82 -0.41]]