Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Python function reshape (data, dimensions) that reshapes the input data according to the provided dimensions and returns the reshaped data as a list,
Write a Python function reshape (data, dimensions) that reshapes the input data according to the provided dimensions and returns the reshaped data as a list, which will contain sublists. For example, reshape $([1,2,3,4,5,6,7,8],(2,4))$ should return the list $[[1,2,3,4], [5,6,7,8]]$. - The data argument will be a single-level sequence - The dimensions argument will be a tuple that will indicate either 2- dimensional or 3-dimensional shape. For example - $(2,5)$ will mean that there will be 2 rows and 5 columns in the reshaped data - $(2,3,4)$ will mean that there will be 2 elements in the $x$- dimension, 3 in the $y$-dimension, and 4 in the z-dimension. - You must check that input data can be reshaped as specified in the dimensions argument. For example, a data sequence with 15 values cannot be reshaped into a $3 \times 42 \mathrm{D} $-array, but it can be reshaped into a $3 \times 52 \mathrm{D}$-array. If data and dimensions are incompatible, your function will raise a AssertionError exception. - If the dimensions value is not a 2- or a 3-tuple, then your function will raise a AssertionError as well cs.VS. 1086||
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