Question

Consider the matrix list x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. Write...

  1. Consider the matrix list x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. Write a list comprehension to extract the first column of the matrix [1, 4, 7]. Write another list comprehension to create a vector of twice the square of the middle column.

Homework Answers

Answer #1

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:)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the matrix A= −2−2 6] [−2−3 5] [3 4−8] [−7−9 18 (all one matrix) (a)...
Consider the matrix A= −2−2 6] [−2−3 5] [3 4−8] [−7−9 18 (all one matrix) (a) How many rows ofAcontain a pivot position? (b) Do the columns ofAspanR4? (c) Does the equationA ~x=~b have a solution for every~b∈R^4? (d) Would the equation A~x=~0 have a nontrivial solution? (e) Are the columns of A linearly independent? (~x is vector x)
2. Write the output matrix “v” t = [2:4]; k = [1:3]; v = t.*k –...
2. Write the output matrix “v” t = [2:4]; k = [1:3]; v = t.*k – k.^2 4. Given: D = [1 2 3 4 5 6 7 8 9] (3x3) . Which command will extract the submatrix [1 2 3 4 5 6] (2x3) ? a. D[1:2,1:3] b. D(1,2 ;1,3) c. [D(1:2),D(1:3)] d. D(1:2,1:3) 14. What will be the dimension of matrix B? B=[ones(3) zeros(3) rand(3); 2*eye(9)] 18. Find the value of “C” A=1:2:10; B=linspace(1,5,5); C = length(A)*B(2)+A(5)*B(3); 19....
Consider the following data: 6, 8, 2, 3, 4, 4, 5, 5, 9, 6, 6, 7,...
Consider the following data: 6, 8, 2, 3, 4, 4, 5, 5, 9, 6, 6, 7, 7 ,7, 7, 8, 8, 8, 8, 9, 9. What type of distribution is this?
A:  8   6   5   8   9   5   3   7   9   3   5   7   9   3   6   4  ...
A:  8   6   5   8   9   5   3   7   9   3   5   7   9   3   6   4   5   8   5   3   9 B:  3   7   9   3   5   7   9   6   8   3   5   9   6   7   8   3   7   9   5   2   8 C:  5   9   6   7   8   3   7   9   5   2   8   8   6   5   8   9   5   4   7   8   5 Using the data from the Production Run Population table what type of graph is not appropriate to...
Given the following unordered array: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]...
Given the following unordered array: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] W X D T P N R Q K M E If the array was being sorted using the SHELL sort and the halving method, and sorting into ASCENDING order as demonstrated in the course content, list the letters in the resulting array, in order AFTER the FIRST pass. [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
Following is a preview of the matrix x: Code: [,1] [,2] [,3] [1,] 1 3 5...
Following is a preview of the matrix x: Code: [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 Write the code that return the output: [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 [3,] 7 8 9
Consider the following: period 1, 2, 3, 4, 5, 6, 7, 8 demand 7, 8, 9,...
Consider the following: period 1, 2, 3, 4, 5, 6, 7, 8 demand 7, 8, 9, 10, 14, 16, 13, 16 a. using a trend projection, forecast the demand for period 9 b. calculate the MAD for this forecast Show all work! do not use excel or phstat!!!
LINEAR ALGEBRA For the matrix B= 1 -4 7 -5 0 1 -4 3 2   ...
LINEAR ALGEBRA For the matrix B= 1 -4 7 -5 0 1 -4 3 2    -6 6    -4 Find all x in R^4 that are mapped into the zero vector by the transformation Bx. Does the vector: 1 0 2 belong to the range of T? If it does, what is the pre-image of this vector?
#2. For the matrix A =   1 2 1 2 3 7 4 7...
#2. For the matrix A =   1 2 1 2 3 7 4 7 9   find the following. (a) The null space N (A) and a basis for N (A). (b) The range space R(AT ) and a basis for R(AT ) . #3. Consider the vectors −→x =   k − 6 2k 1   and −→y =   2k 3 4  . Find the number k such that the vectors...
Matrix A= -2 1 0 2 -3 4 5 -6 7 vector u= 1 2 1...
Matrix A= -2 1 0 2 -3 4 5 -6 7 vector u= 1 2 1 a) Is the vector u in Null(A) Explain in detail why b) Is the vectro u in Col( A) Explain in detail why