0
0
SciPydata~10 mins

Why spatial algorithms solve geometry problems in SciPy - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the spatial module from scipy.

SciPy
from scipy import [1]
Drag options to blanks, or click blank then click option'
Aspatial
Boptimize
Cstats
Dintegrate
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like stats or optimize.
Forgetting to import the spatial module.
2fill in blank
medium

Complete the code to create a KDTree from a list of points.

SciPy
tree = spatial.[1](points)
Drag options to blanks, or click blank then click option'
AConvexHull
BVoronoi
CDelaunay
DKDTree
Attempts:
3 left
💡 Hint
Common Mistakes
Using ConvexHull or Voronoi which are different geometry structures.
Confusing KDTree with Delaunay triangulation.
3fill in blank
hard

Fix the error in the code to query the nearest neighbor of a point using KDTree.

SciPy
distance, index = tree.[1]([1.0, 2.0])
Drag options to blanks, or click blank then click option'
Aquery_ball_point
Bquery
Cnearest_neighbor
Dfind_nearest
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like nearest_neighbor or find_nearest.
Using query_ball_point which returns all neighbors within a radius.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each point to its distance from the origin if the distance is less than 5.

SciPy
distances = {tuple(point): [1] for point in points if [2] < 5}
Drag options to blanks, or click blank then click option'
Asum(point**2)**0.5
Bsum(point**2)
Csum(x**2 for x in point)**0.5
Dlen(point)
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum(point**2) which causes an error because point is a list.
Using len(point) which is not a distance.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each point's index to its distance from the origin if the distance is greater than 2.

SciPy
dist_map = { [1]: [2] for [3] in enumerate(points) if [2] > 2 }
Drag options to blanks, or click blank then click option'
Ai
Bsum(x**2 for x in point)**0.5
C(i, point)
Ddist = sum(x**2 for x in point)**0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to assign inside the dictionary key or value.
Using incorrect unpacking in the for loop.