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
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fdbc56138-9a19-4823-89b1-5c42047e882e%2Fdabdfad1-3aa3-458c-9c9c-f75cc0fda043%2Fhkxaskd_processed.png&w=3840&q=75)
Transcribed Image Text: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
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
