In: Computer Science
Hello,
let me write the function definition for the first part of your problem, which says "Write a list comprehension to extract the first column of the matrix".(Since you didn't specified any language so providing the code in python language,)
code starts here:-
def first_column(l):
column=[]
for i in l:
column.append(i[0])
return column
code ends here:-
the above defined function takes a matrix list as a parameter and then returns the list of all elements present in the first column of matrix.
if the function is called as
print(first_column([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
then it will produce output as :-
let me show the snapshot of code:-(with the calling of the function)
let us move to the second part of the problem which states that "Write another list comprehension to create a vector of twice the square of the middle column."
let us write function for that:-
code starts here:-
def problem2(l):
column=[]
for i in l:
column.append(i[1]*i[1]*2)
return column
code ends here:-
when above function is called with the given list as a parameter as :-
print(problem2([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
then it gives the output as:-
let me show the snapshot of the code with calling the function with given list:-
i hope i was able to solve your problem to a greater extent, please feel free to comment your queries, i will surely respond to them. Please consider my efforts and please upvote my solution.
Thanku:)