python/seshft.py
changeset 0 0efde00f9229
equal deleted inserted replaced
-1:000000000000 0:0efde00f9229
       
     1 #!/usr/bin/python
       
     2 # given A and B arrays, returns C = [<-A-> 0
       
     3 #                                    0  <-B->] with B shifted east by N cols
       
     4 
       
     5 import pylab as pl
       
     6 from scipy import signal
       
     7 
       
     8 def seshft(A, B, N):
       
     9     Arows, Acols = pl.atleast_2d(A).shape
       
    10     Brows, Bcols = pl.atleast_2d(B).shape
       
    11 
       
    12     if N>=0:
       
    13         n = Arows+Brows
       
    14         m = max(Acols, Bcols+N)
       
    15         C = pl.zeros((n, m))
       
    16         C[:Arows, :Acols] = A
       
    17         C[Arows:, N:N+Bcols] = B
       
    18 
       
    19     else:
       
    20         N = -N
       
    21         n = Arows+Brows
       
    22         m = max(Acols+N, Bcols)
       
    23         C = pl.zeros((n, m))
       
    24         C[:Arows, N:N+Arows] = A
       
    25         C[Arows:, :Bcols] = B
       
    26 
       
    27     return C
       
    28 
       
    29 if __name__== "__main__":
       
    30     a = "A = pl.eye(3)"
       
    31     b = "B = pl.eye(10)"
       
    32     n = "N = 0"
       
    33     exec(a)
       
    34     exec(b)
       
    35     exec(n)
       
    36     print a, b, n
       
    37     C = seshft(A, B, N)
       
    38     print C