CS512 – Assignment 1 solution

$25.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

 

  • Write a Python program that creates a matrix of 10 by 10 using the Data provided below.
    1. Place the following data into a file and read the data into the matrix from a file called “Data.txt”
    2. Use random number to select three columns (ex: columns 3, 5, and 9) sort each column in ascending order and make a matrix of 10 by 3 using these three columns
    3. Use random number to select another distinct set of three columns (ex: columns 4, 8, 1). sort each column in descending order and make a matrix of 10 by 3 using these three columns – Call it matrix2. Note that the columns in Matrix 1 should not include any of the columns in Matrix 2
    4. Add the two matrices to each other and put the result into another 10 by 3 matrix call it matrix3
    5. Add the content of each row of Matrix 3 and put it into a new 10 by 1 matrix call it Matrix 4.
    6. Sort Matrix4 in Ascending order

 

You can use the following 10 by 10 in a file to get started:

 

26          8            2            12          67          89          8            78          56          7

13          9            57          11          10          99          15          90          88          15

6            23          28          32          53          59          48          41          60          62

17          6            93          95          20          25          29          31          71          30

16          13          26          22          14          66          71          5            2            91

40          53          22          18          44          73          77          84          89          88

34          54          89          8            65          74          96          3            1            80

14          28          39          44          86          88          75          77          93          4

65          66          82          97          51          41          28          33          55          79

13          48          71          98          26          38          55          59          7            19

 

Your output should be as follows:

 

 

 

The original matrix is as follows:

26          8            2            12          67          89          8            78          56          7

13          9            57          11          10          99          15          90          88          15

6            23          28          32          53          59          48          41          60          62

17          6            93          95          20          25          29          31          71          30

16          13          26          22          14          66          71          5            2            91

40          53          22          18          44          73          77          84          89          88

34          54          89          8            65          74          96          3            1            80

14          28          39          44          86          88          75          77          93          4

65          66          82          97          51          41          28          33          55          79

13          48          71          98          26          38          55          59          7            19

 

Suppose your first three random numbers are 3, 1, and 9. So you your out should prints:

The first three random numbers are 3, 1, and 9 which makes Matrix 1 as follows:

2            26          56

57          13          88

28          6            60

93          17          71

26          16          2

22          40          89

89          34          1

39          14          93

82          65          55

71          13          7

 

Adding Matrix1 and Matrix2 gives Martix3 which is:

 

 

 

 

Suppose the next first three random numbers are 3, 1, and 9. So you your out should prints:

The first three random numbers are 3, 1, and 9 which makes Matrix 1 as follows:

2            26          56

57          13          88

28          6            60

93          17          71

26          16          2

22          40          89

89          34          1

39          14          93

82          65          55

71          13          7

The sorted version of Matrix1 is :

2            6            1

22          13          2

26          13          7

28          14          55

39          16          56

57          17          60

71          26          71

82          34          88

89          40          89

93          65          93

 

 

 

Suppose the next set of three random numbers are 5, 2, and 7. So you your output should prints:

The second set of three random numbers are 5, 2, and 7 which makes Matrix 2 as follows:

67          8            8

10          9            15

53          23          48

20          6            29

14          13          71

44          53          77

65          54          96

86          28          75

51          66          28

26          48          55

Sorting Matrix 2 in descending order we get:

86          66          96

67          54          77

65          53          75

53          48          71

51          28          55

44          23          48

26          13          29

20          9            28

14          8            15

10          6            8

 

 

 

 

 

Adding the contents of the Matrix1 and Matrix2, and put the result in one column Matrix called Matrix 3

Matrix 1:                                         Matrix 2                                                        Matrix 3

2            26          56                        86          66          96                                      332

57          13          88                        67          54          77                                      356

28          6            60                        65          53          75                                      287

93          17          71                        53          48          71                                       353

26          16          2                          51          28          55                                       178

22          40          89                        44          23          48                                       266

89          34          1                          26          13          29                                       192

39          14          93                        20          9            28                                       203

82          65          55                        14          8            15                                       239

71          13          7                          10          6            8                                         115

 

After Sorting Matrix 3 you get:

115

178

192

203

239

266

287

332

353

356

 

 

 

 

main program should look as follows:

  • OriginalMatrix = A1Object.getDataFromDataFile()
  • #Printing(OriginalMatrix)
  • ColA, ColB, ColC = GetThreeRandomNumber(OriginalMatrix)
  • Matrix1 = MakeMatrix(OrioginalMatrix, ColA, ColB, ColC)
  • #Printing(Matrix1)
  • ColD, ColE, ColF = GetThreeRandomNumber(OriginalMatrix, ColA, CoilB, ColC)
  • Matrix2 = MakeMatrix(OrioginalMatrix, ColD, ColE, ColF)
  • #Printing(Matrix2)
  • Matrix3 = AddingMatrices(Matrix1, Matrix2)
  • #Printing(Matrix3)
  • Matrix4 = AddingContentOfEachRow(Matrix3)
  • #Printing(Matrix4)
  • 0Matrix5 = Sorting(Matrix4)
  • #Printing(Matrix5)
  • PrintOutput (OriginalMatrix, Matrix1, Matrix2, Matrix3, Matrix4, Matrix5)