Using DASK in Python to solve this problem. Given a dask array, compute the difference along axis 0 using mean squared error This can be done without loops -- think outside of the box! This also needs to work for 1D, 2D, 3D, 4D, etc. def sequential_MSE_axis0 (anArray): # this does use the earlier MSE implementation n_elements_axis0 = anArray. shape [0] - 1 anArray.shape[0] results = da.zeros(n_elements_axis0) for i in range(n_elements_axis0): results[i] = MSE (anArray[i], anArray[i+1]) return results Complete the function below. Don't call . compute() Test Result oneDda.arange(4); print (all (isclose(a, b) for a, b in zip (MSE_axis0 (oneD), [1., 1., 1.]))) twoD = True da.arange(4).reshape((2,2)); print (all(isclose(a, b) for a, True b in zip (MSE_axis 0 (twoD), [4.]))) = threeD da.arange(8).reshape((2, 2,2)); print (all(isclose(a, b). for a, b in zip (MSE_axis0 (threeD).compute(), [16.]))) True def MSE_axis0 (anArray): ## WRITE YOUR CODE HERE

icon
Related questions
Question
Using DASK in Python to solve this problem.
Given a dask array, compute the difference along axis 0 using mean squared error
This can be done without loops -- think outside of the box! This also needs to work
for 1D, 2D, 3D, 4D, etc.
def sequential_MSE_axis0 (anArray):
# this does use the earlier MSE implementation
n_elements_axis0 = anArray. shape [0] - 1
anArray.shape[0]
results = da.zeros(n_elements_axis0)
for i in range(n_elements_axis0):
results[i] = MSE (anArray[i], anArray[i+1])
return results
Complete the function below. Don't call . compute()
Test
Result
oneDda.arange(4); print (all (isclose(a, b) for a, b in
zip (MSE_axis0 (oneD), [1., 1., 1.])))
twoD =
True
da.arange(4).reshape((2,2)); print (all(isclose(a, b) for a,
True
b in zip (MSE_axis 0 (twoD), [4.])))
=
threeD da.arange(8).reshape((2, 2,2)); print (all(isclose(a, b).
for a, b in zip (MSE_axis0 (threeD).compute(), [16.])))
True
def MSE_axis0 (anArray):
## WRITE YOUR CODE HERE
Transcribed Image Text:Using DASK in Python to solve this problem. Given a dask array, compute the difference along axis 0 using mean squared error This can be done without loops -- think outside of the box! This also needs to work for 1D, 2D, 3D, 4D, etc. def sequential_MSE_axis0 (anArray): # this does use the earlier MSE implementation n_elements_axis0 = anArray. shape [0] - 1 anArray.shape[0] results = da.zeros(n_elements_axis0) for i in range(n_elements_axis0): results[i] = MSE (anArray[i], anArray[i+1]) return results Complete the function below. Don't call . compute() Test Result oneDda.arange(4); print (all (isclose(a, b) for a, b in zip (MSE_axis0 (oneD), [1., 1., 1.]))) twoD = True da.arange(4).reshape((2,2)); print (all(isclose(a, b) for a, True b in zip (MSE_axis 0 (twoD), [4.]))) = threeD da.arange(8).reshape((2, 2,2)); print (all(isclose(a, b). for a, b in zip (MSE_axis0 (threeD).compute(), [16.]))) True def MSE_axis0 (anArray): ## WRITE YOUR CODE HERE
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 1 steps

Blurred answer