联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2019-03-20 10:31

CS112 Homework 4: Memory – Groups Allowed

Due: Sun, Mar 17th, 11:59pm

As this is a Homework, you can read any and all materials, ask us questions, talk with other

students, and learn however you best learn in order to solve the task. Just create your own

solution from those experiences, and turn in your work.

Notes

The purpose of this homework is to provide additional practice with the use of memory and

aliases

We will be using function definitions for this homework. Remember, don't call input() or

print() anywhere, just use the parameters provided and return statements.

You cannot import any module. When a task has individual restrictions, note them, as we

will remove points for any task that does not follow the requirements.

A tester has been included with this assignment. Grading is based on the fraction of

passing tests. You can run it like this:

python3 testerH4.py gmason76_210_H4.py

For the tester, if you only want to test some functions, you can specify which functions:

python3 testerH4.py gmason76_210_H4.py transpose_matrix

Turning It In

Add a comment at the top of the file that indicates your name, userID, G#, lab section, a

description of your collaboration partners, as well as any other details you feel like sharing.

Please also mention what was most helpful for you. Once you are done, run the testing script

once more to make sure you didn't break things while adding these comments. If all is well, go

ahead and turn in just your .py file you've been working on, named with our usual convention

(see above), over on BlackBoard to the correct lab assignment. Please don't turn in the tester file

or any other extra files, as it will just slow us down.

Grading Rubric

Pass shared test cases 100 (zero points for hard-coding)

----------------------------------------------------------------

TOTAL: 100

Tasks

def transpose_matrix(mat)

Creates and returns a new matrix that is the transpose of mat

https://en.wikipedia.org/wiki/Transpose

mat is a nested list (e.g. [[1,2,3], [4,5,6]] and is guaranteed to have a rectangular shape

and more than one elements

You’re not allowed to use slicing, or import modules, or use the list comprehension syntax

The only functions you’re allowed to use are: len() , range() , append()

Examples:

transpose_matrix([[1,2,3], [4,5,6]]) → [[1,4], [2,5], [3,6]]

transpose_matrix([[1,2],[3,4],[5,6]]) → [[1,3,5], [2,4,6]]

def diagonal_matrix(mat)

Converts a square matrix mat into a lower diagonal matrix

https://en.wikipedia.org/wiki/Triangular_matrix

After the conversion the values on the diagonal will be the sum of the deleted elements in

the respective row

Return value is None. Variable mat is directly modified in memory

mat is a nested list (e.g. [[1,2,3], [4,5,6], [7,8,9]] and is guaranteed to have a square

shape of size at least 2x2

You’re not allowed to use slicing, or import modules, or use the list comprehension syntax

The only functions you’re allowed to use are: len() , range() and the del keyword

Examples:

diagonal_matrix([[1,2,3], [4,5,6], [7,8,9]]) → [[6], [4, 11], [7, 8, 9]]

diagonal_matrix([[1,2],[3,4]]) → [[3], [3,4]]

def reduce_matrix(mat)

Reduces the size of matrix mat in half, in both dimensions, by merging adjacent elements

The new values of the matrix are the average of the respective merged elements

Return value is None. Variable mat is directly modified in memory

mat is a nested list (e.g. [[1,2,3,4], [5,6,7,8]] and is guaranteed to be non-empty and have

a rectangular shape. Both dimensions are even numbers

You’re not allowed to use slicing, or import modules, or use the list comprehension syntax

The only functions you’re allowed to use are: len() , range() and the del keyword

Examples:

reduce_matrix([[1,2],[3,4]]) → '[[2.5]]'

reduce_matrix([[1,2,3,4],[5,6,7,8],[9,8,7,6],[5,4,3,2]]) → '[[3.5,5.5],[6.5,4.5]]'


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp