Question
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
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
Youre not allowed to use slicing, or import modules, or use the list comprehension syntax
The only functions youre 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]]'
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started