Question

Can someone solve these for me using only len(), range(), append(), and del keyword when needed...

Can someone solve these for me using only len(), range(), append(), and del keyword when needed as the directions state? No list comprehension, slicing, or importing modules. No chr or index(i) functions.

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]]'

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Can someone solve these for me using only len(), range(), append(), and del keyword when needed...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python code: using only len(), range(), append(), and del keyword when needed as the directions state?...

    Python code: using only len(), range(), append(), and del keyword when needed as the directions state? No list comprehension, slicing, or importing modules. Please and thank you. 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 modi ed in memory mat is a nested list (e.g. [[1,2,3], [4,5,6],...

  • Can some help me solve these? I am confused on where to start. I know in...

    Can some help me solve these? I am confused on where to start. I know in some cases, since there are no arguments, I can use *. Function 3: In this function you must both return a value and modify in-place the input parameter (when needed). The only functions you are allowed to use are range(), len(), append(), insert(), remove(), pop() and the del keyword. • Examples: return value argument value after return ◦ func3([4,-3,7,-5,1]) → [-3,-5] [4,7,1] ◦ func3([4,-3,7,-5,1],...

  • Fit to page ID Page view A Re - + of the cropped tile, width (int)...

    Fit to page ID Page view A Re - + of the cropped tile, width (int) is the width of the cropped tile Retur ed image that is a 3D list of int Example crop ([ LLU ,1, ,2,2), (3,3,3]], [(4,4,4], [5,5,5),(6,6,6]], [[7,7,7], [8,8,8], [9,9,9]] ), (0,0), 1, 2) [[[1,1,1], [2,2,2]]] color2gray(image) Description: It takes a color image (3D list) and returns a new grayscale image (2D list) where each pixel will take the average value of the three color...

  • PYHTON CODING FUNCTIONS HELP Part 2. Also need help with these last functions. Requirements/restraints and the...

    PYHTON CODING FUNCTIONS HELP Part 2. Also need help with these last functions. Requirements/restraints and the map referred to is pictured in the screenshot. Need help with these 4 tasks: Function 4: def is_map(map) : given a map (see screenshot), does it meet the following criteria? 1) it is a list of lists of values of type int; 2) it has at least one row and one column; 3) it’s rectangular (all sub-lists are same length); 4) only non-negative ints...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT