Using nested for loops, write a function that returns a list of the sums by rows and columns for a given matrix. For example, your function should return [[6,15,24],[12,15,18]] for a matrix argument [[1,2,3],[4,5,6],[7,8,9]]. in python
Added by Andrew F.
Step 1
Define a function that takes a matrix as an argument. Show more…
Show all steps
Your feedback will help us improve your experience
James Kiss and 92 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
(Sum elements column by column) Write a function that returns the sum of all the elements in a specified column in a matrix using the following header: def sumColumn(m, columnIndex): Write a test program that reads a $3 \times 4$ matrix and displays the sum of each column. Here is a sample run:
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Willis J.
Python program to calculate the average of a given array of numbers and output all numbers that are higher than the average by more than 20%. Let 'a' be a Python list, then we can declare a list with values as: a = [2, 4, 3, 10, 33]. Standard functions can be used to calculate the sum or the length (number of elements) of a list: sum(a), len(a). One of the most common operations with lists is iteration. Then a code can be repeatedly applied to each element of the list.
Shelayah R.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD