Question: Lecture # 3, Exercise 1: The purpose of this exercise is to practice for loop. The sample code below, fills a 3X3 matrix, row by

Lecture # 3, Exercise 1: The purpose of this exercise is to practice for loop. The sample code below, fills a 3X3 matrix, row by row. It stars from the first row, and moves through all columns until it hits the last column. Then moves to the next row and moves through all the columns. Let's see how this following code is implemented: k=0 Y = np.arange(0,9) X = np.ones(3,3)) # creates an array of integers # creates a 3X3 matrix #moves through rows #moves through columns for i in range(0, 3): for j in range(0,3): X[ii] = Y[k] k += 1 print(X) The first for loop controls the row number and the second loop, controls the column. The variable "k" is independent of the any of the for loops. Nested for loop is one of the most important techniques used in programing so please make sure you understand how this code works. Practice: Copy the given matrix into your editor. Write a program that uses nested for loop to print the transpose of this matrix. X = [[1, 2, 3], [4, 5, 6],[7, 8, 9]]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
