Question

In: Computer Science

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.

Solutions

Expert Solution

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


Related Solutions

x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7...
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7 9 7 4 6 9 9 -5.48x + 0.17 5.48x + 0.17 -0.17x + 5.48 0.17x + 5.48
Consider the following set of observations: Obs. 1 2 3 4 5 6 7 8 9...
Consider the following set of observations: Obs. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 input 1 2 3 4 5 6 7 8 9 10 11 12 13 14 result 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Enter the data in L1 and L2 in your TI calculator, find the regression line, and construct a scatterplot with the regression line included. Does a line appear to...
Table: x: 6, 2, 15, 9, 12, 5, 8 y: 8, 9, 4, 7, 6, 9,...
Table: x: 6, 2, 15, 9, 12, 5, 8 y: 8, 9, 4, 7, 6, 9, 8 1) Make the scatter diagram. 2) Find the equation of the regression line using the formulas given in class. They must appear the intermediate steps of substitutions. Round the answers to three decimal places. 3) Find the correlation coefficient using the formulas given in class. Steps should appear intermediates of substitutions. Round the answer to three decimal places. 4) Find the value predicted...
1.Consider the program: .data myArray: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10...
1.Consider the program: .data myArray: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 .text la $s0, myArray li $s1, 0 loop: sll $t0, $s1, 2 add $t0, $t0, $s0 lw $s2, 0($t0) lw $s3, 4($t0) add $s2, $s2, $s3 sw $s2, 0($t0) addi $s1, $s1, 1 slti $t1, $s1, 9 bne $t1, $zero, loop .end Explain what does this program do? How is the data bound from the .data segment to the base address register $s0? What...
Given the matrix as shown below n_array = 3 1 8 3 5 7 4 9...
Given the matrix as shown below n_array = 3 1 8 3 5 7 4 9 2 Write a M-file script program that generates this n_array, and answer each question using one line of MATLAB statement. a) Replace the second column of the n_array with a column of 0s b) Replace the element in the second-row, third-column with a zero c) Change the n_array to a 4 x 3 array by adding a row of 0s The end result for...
MATLAB: Matrix M = [ 0 2 3 5; 7 3 8 4 ] Write one...
MATLAB: Matrix M = [ 0 2 3 5; 7 3 8 4 ] Write one command that stores all of the rows of columns 1, 2, and 3 of M into a matrix named M2.
tens Units 1 5 2 3 4 8 5 2 5 6 9 6 1 3...
tens Units 1 5 2 3 4 8 5 2 5 6 9 6 1 3 5 4 7 9 7 0 0 4 5 6 9 9 8 1 3 5 6 8 9 9 0 1 2 3 5 9 The table represent a random sample of 31 test scores taken from a large lecture class. Find the following [round to 2 decimal points X. XX] a) [2 pts] Find the 5 number summary [L, Q1, Q2, Q3,...
For the following data set, X: 9, 6, 8, 3, 8, 9, 3, 4, 3, 7:...
For the following data set, X: 9, 6, 8, 3, 8, 9, 3, 4, 3, 7: Calculate: 1. Variance 2. Mode 3. Mean 4. Mean Average Deviation (MAD) about the mean 5. Median
ID X Y 1 2 3 2 3 6 3 4 6 4 5 7 5...
ID X Y 1 2 3 2 3 6 3 4 6 4 5 7 5 8 7 6 5 7 7 6 7 8 8 8 9 7 8 10 12 11 Test the significance of the correlation coefficient. Then use math test scores (X) to predict physics test scores (Y).  Do the following: Create a scatterplot of X and Y. Write the regression equation and interpret the regression coefficients (i.e., intercept and slope). Predict the physics score for each....
3 6 4 8 1 10 2 9 11 12 15 22 3 6 7 5...
3 6 4 8 1 10 2 9 11 12 15 22 3 6 7 5 8 1 12 14 Each column represents a different treatment given to sick rats. Each cell is a different rat. Use statistical analysis and use post hoc testing using contrasts to find the best treatment. Treatment 1: vitamins Treatment 2: prescription pills Treatment 3: brain surgery Treatment 4: shock therapy Treatment 5: dietary changes
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT