Question: 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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!