1 / 28

CS 177 Week 9 Recitation Slides

CS 177 Week 9 Recitation Slides. Matrix Encoding Matrix Multiplication Trees as Lists Columnar Transposition. Announcements. Matrix Encoding: Row by Row. A. A = [1, 1, 0, 3, 2, 8, 5, -3, 5] rowLength = 3 A[ rowLength *y +x]. Matrix Encoding: Column by Column. A.

Download Presentation

CS 177 Week 9 Recitation Slides

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 177 Week 9 Recitation Slides Matrix Encoding Matrix Multiplication Trees as Lists Columnar Transposition

  2. Announcements

  3. Matrix Encoding: Row by Row A • A = [1, 1, 0, 3, 2, 8, 5, -3, 5] • rowLength = 3 • A[rowLength*y +x]

  4. Matrix Encoding: Column by Column A • A = [1, 3, 5, 1, 2, -3, 0, 8, 5] • columnLength = 3 • A[columnLength*y +x]

  5. Matrix Multiplication C A B C A B = *

  6. Matrix Multiplication C A B

  7. Matrix Multiplication C A B

  8. Matrix Multiplication C A B

  9. Matrix Multiplication C A B

  10. Matrix Multiplication C A B

  11. Matrix Multiplication C A B

  12. Matrix Multiplication C A B

  13. Matrix Multiplication C A B

  14. Matrix Multiplication C A B

  15. Indexes in Matrix Multiplication

  16. Matrix Multiplication A = [[1, 1, 1] ,[2,2,2] ,[3,3,3]] B = [[1, 2, 3], [4,5,6] ,[7,8, 9]] C = [3*[0] for i in range(3)] for i in range(3): for j in range(3): for k in range(3): C[i][j] = C[i][j] + ( A[i][k] * B[k][j])

  17. Trees as Lists Root Root L2 Root L2 L0 L1 L3 L4 Leaf1 Leaf2 Leaf3 L0 L1 L3 L4 L5 L5 L6 Lists are powerful structures Lists can be used to build trees

  18. Simple trees Tree1 Tree2 Tree3 L0 L1 L2 L0 L1 L0 L5 L3 L4 L1 L2 >>> Tree1 = ['L0', 'L1'] >>>Tree2 = ['L0', 'L1', 'L2'] >>>Tree3 = ['L0', 'L1', 'L2','L3', 'L4', 'L5']

  19. Tree 0 1 0 1 0 1 L0 L1 L2 L3 >>> Tree = [['L0', 'L1'], ['L2','L3']] What is tree[1][0]? What is tree[0][1]?

  20. Question Tree A B C D E F Build the list representing the following tree, (and call it tree)

  21. Answer Tree A B C D E F >>>Tree = [[‘A’,’B’],[’C’,’D’],[’E’,’F’]]

  22. Question Tree B D E F X Y Z Build the following tree:

  23. Answer 0 Tree 1 2 0 1 0 1 0 1 B 0 1 D 0 E F X Y Z Build the following tree >>> Tree = [[['X','Y'],'B'],[['Z'],'D'] ,['E','F'] ]

  24. Question 0 Tree 1 2 0 1 0 1 0 1 B 0 1 D 0 E F X Y Z How to access: X, Z, and E?

  25. Answer 0 Tree 1 2 0 1 0 1 0 1 B 0 1 D 0 E F X Y Z >>>Tree[0][0][0] ‘X’ >>>Tree[1][0][0] ‘Z’ >>>Tree[2][0] ‘E’

  26. Columnar Transposition S = [[‘P’, ‘R’, ‘O’], [‘G’, ‘R’, ‘A’], [‘M’, ‘~’, ‘~’]] How to get “PROGRAM”? How to get “MGP~RP~AO”?

  27. D = ""for i in range(0,3):       for j in range(0,3):               D = D + S[i][j]print(D) D = ""for i in range(0,3):       for j in range(0,3):               D = D + S[3-1-j][i]print(D)

  28. ANY QUESTIONS?

More Related