
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Write and test a Python function, that makes use of numpy, to return the sum of the elements on
the
main diagonal (upper left to lower right) of a square matrix. In linear algebra, this value is called
the
trace of the matrix.
For example, with a matrix represented as a list of lists eg. [[9, 8, 7], [6, 5, 4], [3, 2, 1]], your
function
should return (9 + 5 + 1) = “15”
Your Python function solution should work for any sized square matrix passed to it. Demonstrate
that this is the case with 3x3, 4x4, and 6x6 matrix examples.
![Write and test a Python function, that makes use of numpy, to return the sum of the elements on the
main diagonal (upper left to lower right) of a square matrix. In linear algebra, this value is called the
trace of the matrix.
For example, with a matrix represented as a list of lists eg. [[9, 8, 7], [6, 5, 4], [3, 2, 1]], your function
should return (9 +5+1) = "15"
Your Python function solution should work for any sized square matrix passed to it. Demonstrate
that this is the case with 3x3, 4x4, and 6x6 matrix examples.](https://content.bartleby.com/qna-images/question/bb2b6ce6-42d4-40e8-9ef5-9093d65805ca/e684fcf5-0c9a-4f20-9e07-fe439b4f0920/axji9h_thumbnail.png)
Transcribed Image Text:Write and test a Python function, that makes use of numpy, to return the sum of the elements on the
main diagonal (upper left to lower right) of a square matrix. In linear algebra, this value is called the
trace of the matrix.
For example, with a matrix represented as a list of lists eg. [[9, 8, 7], [6, 5, 4], [3, 2, 1]], your function
should return (9 +5+1) = "15"
Your Python function solution should work for any sized square matrix passed to it. Demonstrate
that this is the case with 3x3, 4x4, and 6x6 matrix examples.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 4 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Use Python for this question: Implement a function findMixedCase that accepts a single argument, a list of words, and returns the index of the first mixed case word in the list, if one exists, (a word is mixed case if it contains both upper and lower case letters), and returns -1 if the all words are either upper or lower case Output for this question is in the attached image:arrow_forwardSuppose a node of a linked list is defined as follows in your program: typedef struct{ int data; struct Node* link; } Node; Write the definition of a function, printOdd(), which displays all the odd numbers of a linked list. What will be the time complexity of printOdd()? Express the time complexity in terms of Big-O notation.arrow_forwardwrite a Python function that takes in a list of integers (nums) and finds whether the list consists of any duplicate numbers, the function returns True or False accordingly (Note: this is not a linked list, just a Python list). Function must run in place and cannot use Python’s built-in Set() structure. Make sure to provide the most efficient algorithm in terms of its time and space complexity.arrow_forward
- e) The power to a motor in a group conveyor system is controlled by the state of Four Sensor Switches A,B,C and D. The motor is to be switched on when:- All sensor switches are OPEN- Any one switch is CLOSED and the remaining three OPEN- B and C CLOSED, A and D OPEN- A and D CLOSED, B and C OPEN Assuming Switch closed = logic 1 and Switch open =0 Design the logic circuit to control the motor using NOR gates only [5 marks]arrow_forwardYou are given an array-like data structure Listy which lacks a size method. It does, however, have an elementAt ( i) method that returns the element at index i in 0( 1) time. If i is beyond the bounds of the data structure, it returns -1. (For this reason, the data structure only supports positive integers.) Given a Listy which contains sorted, positive integers, find the index at which an element x occurs. If x occurs multiple times, you may return any index. Write code with explanationarrow_forwardImplement a function countMultiples in Python that: accepts a single argument, a 2-dimensional list (e.g, list of lists) containing non-negative integers, and returns the count of those integers that are multiples of 5 but that are not not multiples of 10. (e.g., 65 should be counted, but 80 should not be counted) sample usage: >>> countMultiples( [[1,2,3],[4,5],[6,7,8,9]] ) # 5 counts1arrow_forward
- Create a function that takes the dimensions of two triangles (as arrays) and checks if the first triangle fits into the second one. Examples does TriangleFit([1, does TriangleFit([1, does TriangleFit([1, does TriangleFit([1, 1, 1], [1, 1, 1]) → true 1, 1], [2, 2, 2]) → true 2, 3], [1, 2, 2]) → false 2, 4], [1, 2, 6]) → falsearrow_forwardImplement the following function that returns a vector of vectors of Item, each of which is a subset of elements chosen from the given vector a[first…last]: /* if a is {1,2,3}, first=0, last=2, the function shall returns a vector of the following vectors: {}, {1}, {2}, {3}, {1,2},{1,3}, {2,3},{1,2,3}, all subsets of a[0…2]. Precondition: last-first+1>=1, i.e., there is at least one element in the a[first…last] Note 1)if the length of a[first…last] is n, then the function should return a vector of 2n vectors 2) The order of these subsets does not need to match what’s listed here… */ vector<vector<int>> subsets (const vector<int> & a, int first, int last) codearrow_forwardCreate a function append(v, a, n) that adds to the end of vector v a copy of all the elements of array a. For example, if v contains 1,2, 3, and a contains 4, 5, 6, then v will end up containing 1, 2, 3, 4, 5,6. The argument n is the size of the array. The argument v is a vector ofintegers and a is an array of integers. Write a test driver.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education