This notebook walks you through how to implement simple functions that transpose matrix $ A $, storing the result in matrix $ B $.
We will use some functions that are part of our laff library (of which this function will become a part) as well as some routines from the FLAME API (Application Programming Interface) that allows us to write code that closely resembles how we typeset algorithms using the FLAME notation. These functions are imported with the "import laff as laff" and "import flame" statements.
Write your
Transpose_unb_var1( A, B )
routine, using the Spark webpage and the laff.copy
routine.
# insert code here
Let's quickly test the routine by creating a 5 x 4 matrix $ A $ and a 4 x 5 matrix $ B $ and then transposing $ A $, overwriting $ B $ with the result.
from numpy import random
from numpy import matrix
A = matrix( random.rand( 5,4 ) )
B = matrix( random.rand( 4,5 ) )
print( 'A ' )
print( A )
print( 'B before =' )
print( B )
Transpose_unb_var1( A, B )
print( 'A ' )
print( A )
print( 'B after =' )
print( B )
Bingo, it seems to work!
Now, an alternative routine that accesses the matrix by rows.
Use the Spark webpage to generate the routine
Transpose_unb_var2( A, B )
.
# insert code here
Test your routine with the following
A = matrix( random.rand( 5,4 ) )
B = matrix( random.rand( 4,5 ) )
print( 'A ' )
print( A )
print( 'B before =' )
print( B )
Transpose_unb_var2( A, B )
print( 'A ' )
print( A )
print( 'B after =' )
print( B )
Copy and paste the code into PictureFLAME , a webpage where you can watch your routine in action. Just cut and paste into the box.
Disclaimer: we implemented a VERY simple interpreter. If you do something wrong, we cannot guarantee the results. But if you do it right, you are in for a treat.
If you want to reset the problem, just click in the box into which you pasted the code and hit "next" again.