Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

I want to make this using javascript

Answered: 1 week ago

Question

5. Describe the relationship between history and identity.

Answered: 1 week ago