In [1]:
from mth309 import *
In [2]:
from numpy import *
In [3]:
A = Matrix(random.randint(-9,9,(3,5)))
A
Out[3]:
 -7 -6  2 -6  7
 -5 -1 -9 -9 -1
 -3  8  5 -6 -5
In [4]:
AT = A.T
AT
Out[4]:
 -7 -5 -3
 -6 -1  8
  2 -9  5
 -6 -9 -6
  7 -1 -5
In [6]:
R = re(AT)
R
Out[6]:
 1 5/7   3/7
 0   1 74/23
 0   0     1
 0   0     0
 0   0     0

How to build a 6x7 with 4-dimensional column space?

Answer: multiply a random 6x4 and a random 4x7

In [17]:
P = random.randint(-9,10,(6,4))
print(P)
Q = random.randint(-9,10,(4,7))
print(Q)
[[ 8 -6 -8 -6]
 [-8 -5 -5  9]
 [ 3  9 -4  8]
 [-4 -5 -2 -9]
 [ 5  3  3  8]
 [ 7  5  1 -3]]
[[-7  9  6  0  2 -2  9]
 [-3  2  8 -4  3  7 -7]
 [ 1 -6 -4 -8 -2  2  4]
 [-1  4 -4 -1 -8 -2  5]]
In [18]:
A = Matrix(dot(P,Q))
In [19]:
A
Out[19]:
 -40  84   56  94  62 -62  52
  57 -16 -104  51 -93 -47 -12
 -60 101   74 -12 -23  33 -12
  50 -70  -20  45  53 -13 -54
 -49  65   10 -44 -51   1  76
 -60  55   90 -25  51  29  17

Can't see by eye that this has a 4D column space, but row-reduction shows it:

In [20]:
re(A)
Out[20]:
 1 -21/10      -7/5       -47/20       -31/20         31/20     -13/10
 0      1 -242/1037    3699/2074     -93/2074    -2707/2074   621/1037
 0      0         1 224847/32840 242909/32840 -193649/32840 15561/3284
 0      0         0            1            1            -1      68/71
 0      0         0            0            0             0          0
 0      0         0            0            0             0          0

How about a more extreme example of a "deficient" column space: a 6x7 with a 1D column space? Same approach works.

In [21]:
P = random.randint(-9,10,(6,1))
print(P)
Q = random.randint(-9,10,(1,7))
print(Q)
A = Matrix(dot(P,Q))
A
[[-8]
 [ 5]
 [ 7]
 [ 2]
 [ 6]
 [ 9]]
[[-1 -8 -9  9  9  4 -7]]
Out[21]:
  8  64  72 -72 -72 -32  56
 -5 -40 -45  45  45  20 -35
 -7 -56 -63  63  63  28 -49
 -2 -16 -18  18  18   8 -14
 -6 -48 -54  54  54  24 -42
 -9 -72 -81  81  81  36 -63
In [22]:
re(A)
Out[22]:
 1 8 9 -9 -9 -4 7
 0 0 0  0  0  0 0
 0 0 0  0  0  0 0
 0 0 0  0  0  0 0
 0 0 0  0  0  0 0
 0 0 0  0  0  0 0