python/seshft.py
author Puneeth Chaganti <punchagan@fossee.in>
Fri, 27 May 2011 14:24:59 +0530
changeset 0 0efde00f9229
permissions -rw-r--r--
Initial commit.

#!/usr/bin/python
# given A and B arrays, returns C = [<-A-> 0
#                                    0  <-B->] with B shifted east by N cols

import pylab as pl
from scipy import signal

def seshft(A, B, N):
    Arows, Acols = pl.atleast_2d(A).shape
    Brows, Bcols = pl.atleast_2d(B).shape

    if N>=0:
        n = Arows+Brows
        m = max(Acols, Bcols+N)
        C = pl.zeros((n, m))
        C[:Arows, :Acols] = A
        C[Arows:, N:N+Bcols] = B

    else:
        N = -N
        n = Arows+Brows
        m = max(Acols+N, Bcols)
        C = pl.zeros((n, m))
        C[:Arows, N:N+Arows] = A
        C[Arows:, :Bcols] = B

    return C

if __name__== "__main__":
    a = "A = pl.eye(3)"
    b = "B = pl.eye(10)"
    n = "N = 0"
    exec(a)
    exec(b)
    exec(n)
    print a, b, n
    C = seshft(A, B, N)
    print C