Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use python and one loop to solve this problem Q6: Secondary Trace You are given a function that takes a square array, matrix, and returns

use python and one loop to solve this problem
image text in transcribed
image text in transcribed
image text in transcribed
Q6: Secondary Trace You are given a function that takes a square array, matrix, and returns the sum of the secondary diagonal values for matrix. This function employs a nested 2D for-loop. Write a function secondary trace single loop that solves the same problem using only one for-loop. For example, on the picture below secondary diagonal consists of values: a03, a12, a21, a30. a00 a01 a02 a03 a10 all a12 a13 a20 a21 a22 a23 a30 a31 a32 a33 def secondary trace (matrix) : 1 Return sum of values on secondary diagonal. >>mO[, 0], [0, 111 > ml[, 1, 1], [2, 2, 21,[3, 3, 311 >>> m2 [[3, 4],[6, 911 >>> secondary trace (m0) >>> secondary trace (ml) >>> secondary trace (m2) 10 Tr TT 11 for i in range (len (matrix)): for j in range (1en (matrix)): if ilen (matrix) - -1: sum += matrix [i] [j] return sum def seconday trace single loop (matrix): IT TT 11 Return sum of values on secondary diagonal >>> mo = [[1, 0], [0, 1]] >>> m2 = [[3, 4], [6, 911 >>> seconday trace single loop (mO) >>>seconday trace single loop (mi) >>> seconday trace single loop (m2) 10 1 YI # YOUR CODE IS HERE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions