Using DASK in Python to solve this problem. Given a 2D dask array, for each row, pick the number closest to 0.5 using dask array functions. A poorly performing sequential implementation has been provided for reference. 1 # A very poor performing sequential implementation def sequential_closest_to_0_5(aA): result = da.zeros(aA.shape[0]) 2 3 4 5 for row in range(aA.shape[0]): closest = None 6 7 8 9 for col in range(aA.shape[1]): if closest is None or abs(aA[row, col] - 0.5) < abs(closest 0.5): closest = aA [row, col] result [row] = closest 10 return result Complete the function below. You should use the abs, argmin, choose, and transpose functions. Don't call compute() aA is assumed to be a dask array already Test print (all(isclose(a, b) for a, b in zip(closest_to_0_5(da.from_array([[1,0.2], [0.6,0.1]])).compute(), [0.2, 0.6]))) def closest_to_0_5 (aA): ## WRITE YOUR CODE HERE Result True
Using DASK in Python to solve this problem. Given a 2D dask array, for each row, pick the number closest to 0.5 using dask array functions. A poorly performing sequential implementation has been provided for reference. 1 # A very poor performing sequential implementation def sequential_closest_to_0_5(aA): result = da.zeros(aA.shape[0]) 2 3 4 5 for row in range(aA.shape[0]): closest = None 6 7 8 9 for col in range(aA.shape[1]): if closest is None or abs(aA[row, col] - 0.5) < abs(closest 0.5): closest = aA [row, col] result [row] = closest 10 return result Complete the function below. You should use the abs, argmin, choose, and transpose functions. Don't call compute() aA is assumed to be a dask array already Test print (all(isclose(a, b) for a, b in zip(closest_to_0_5(da.from_array([[1,0.2], [0.6,0.1]])).compute(), [0.2, 0.6]))) def closest_to_0_5 (aA): ## WRITE YOUR CODE HERE Result True
Related questions
Question
Using Dask in Python
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 1 steps