python/move.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
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
import pylab as pl
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     5
def move(b, nonred, maxi):
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     6
    """ """
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     7
    br, bc = pl.atleast_2d(b).shape
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     8
    b = pl.hstack((b, pl.zeros((br, len(nonred)-bc))))
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     9
    maxi = max(max(nonred)+1, maxi)
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    10
    result = pl.zeros((br, maxi))
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    11
    nonred = pl.array(nonred)
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    12
    result[:,nonred.T]=b
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    13
    return result
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    14
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    15
if __name__== "__main__":
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    16
    
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    17
    s = """b = pl.array([[1, 2], 
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    18
              [9, 10]])"""
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    19
    t = """nonred = pl.array([7, 2])"""
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    20
    u = """maxi = 10"""
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    21
    print s, t, u
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    22
    exec(s)
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    23
    exec(t)
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    24
    exec(u)
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    25
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    26
    print """move(b, nonred, maxi)"""
0efde00f9229 Initial commit.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    27
    print move(b, nonred, maxi)