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.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     1
#!/usr/bin/python
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     2
# given A and B arrays, returns C = [<-A-> 0
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
#                                    0  <-B->] with B shifted east by N cols
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     5
import pylab as pl
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     6
from scipy import signal
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     7
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     8
def seshft(A, B, N):
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     9
    Arows, Acols = pl.atleast_2d(A).shape
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    10
    Brows, Bcols = pl.atleast_2d(B).shape
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    11
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    12
    if N>=0:
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    13
        n = Arows+Brows
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    14
        m = max(Acols, Bcols+N)
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    15
        C = pl.zeros((n, m))
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    16
        C[:Arows, :Acols] = A
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    17
        C[Arows:, N:N+Bcols] = B
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    18
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    19
    else:
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    20
        N = -N
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    21
        n = Arows+Brows
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    22
        m = max(Acols+N, Bcols)
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    23
        C = pl.zeros((n, m))
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    24
        C[:Arows, N:N+Arows] = A
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    25
        C[Arows:, :Bcols] = B
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    26
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    27
    return C
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    28
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    29
if __name__== "__main__":
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    30
    a = "A = pl.eye(3)"
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    31
    b = "B = pl.eye(10)"
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    32
    n = "N = 0"
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    33
    exec(a)
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    34
    exec(b)
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    35
    exec(n)
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    36
    print a, b, n
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    37
    C = seshft(A, B, N)
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    38
    print C