top of page

Python Programming Design experience

Programming in python has given me a good opportunity to solve programming problems using an engineering design approach. A notable example throughout the term involves a python program in which I initially thought I saw a good solution to the problem and began writing it without diverging and looking for other solutions to the problems. After reflecting on the code I had written, I realized that I could write the code in a much more cleaner, efficient way. This artifact shows how I am effectively able to refine and perfect a solution, but also shows that I am still working on my ability to diverge and think of multiple solutions to a problem.

 

The function takes a matrix called mat, which is one large list which contains many sub-lists containing integers, with each sub-list representing a row, and returns its transpose by swapping the rows and columns.

 

I began by understanding the problem, researching what the transpose of a matrix really means. At first, my requirements were just 'the code must work', and I framed the problem as a nested-for loop that iterates through the rows and column of the matrix, swapping the elements as it goes through. I did not see any other solutions at the time, so creating divergent solutions and selecting an approach was skipped. I then began prototyping by writing pseudo-code as a low-fidelidy prototype, shown in figure #1, which is fake code that outlines what the code should do in english. I then wrote the code, shown in figure #2. As shown, this code involves calling another function to create another matrix, and also run through two for loops. Not only is this more complicated, but it involves more lines of code, is less compact and will require more CPU due to the function call to create the new matrix.

 

 

 

 

 

 

 

 

 

 

Figure #1: Shows the pseudo-code for the transpose function

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure #2: Shows the original code for the transpose function

 

 

Reaching the refining stage in my design process, I decided that new objectives to the problem were to write  as little code possible, to maximize code speed, and to maximize code readability. After iterating through this process again, I found that I was able to complete this transpose function with a single line, using a nested list comprehension. This special way of creating a list makes it so no function call is necessary,  and is much more efficient in terms of the number of lines executed. This list comprehension makes the rows of the matrix the columns by going through every value in each column and making it the into the first row, and does this for every column in the range of the matrix column size. Reflecting on this much more efficient, shorter function, I was satisfied with the solution and submitted this as the answer. This artifact is a good example of how I develop my initially weak diverging skills, but also shows my strong prototyping skills as I am able to successfully create a fully functional, 100% fidelidy prototype of the idea I had imagined.

 

 

 

 

 

 

 

 

 

Figure #3: Shows the finalized, shorter and most optimal solution to the problem

 

 

F

bottom of page