-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvfun.py
44 lines (36 loc) · 957 Bytes
/
convfun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import numpy as np
def listtoarr(A):
return np.vstack((np.hstack((A[0],A[1])), np.hstack((A[2],A[3]))))
def blockconv(A):
blk_size=(3,3)
blk_sqrtlen=4
blk_s2len=2
b=0*A
counter=0
Aee=[]
Aem=[]
Ame=[]
Amm=[]
for ii in range(blk_s2len):
for jj in range(blk_s2len):
Ablk=A[6*ii:6*(ii+1),6*jj:6*(jj+1)]
Aee.append(Ablk[0:3, 0:3])
Aem.append(Ablk[0:3, 3:6])
Ame.append(Ablk[3:6,0:3])
Amm.append(Ablk[3:6, 3:6])
B=[listtoarr(Aee), listtoarr(Aem), listtoarr(Ame), listtoarr(Amm)]
B=listtoarr(B)
return B
def blockdiag(M):
zer=np.zeros(M.shape)
Mb=[M, zer, zer, M]
return listtoarr(Mb)
def blockflip(M):
blocksize=3
nblocks=2
blocks=[]
for ii in range(nblocks):
for jj in range(nblocks):
blocks.append(M[3*ii:3*(ii+1), 3*jj:3*(jj+1)])
blocks.reverse()
return listtoarr(blocks)