Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the convex hull function from scipy.spatial.
SciPy
from scipy.spatial import [1] points = [[0, 0], [1, 1], [1, 0], [0, 1]] hull = ConvexHull(points)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or incorrect casing for ConvexHull
Trying to import a non-existent function like convex_hull
✗ Incorrect
The correct function to import is ConvexHull with exact casing from scipy.spatial.
2fill in blank
mediumComplete the code to create a convex hull object from the points array.
SciPy
import numpy as np from scipy.spatial import ConvexHull points = np.array([[0, 0], [1, 1], [1, 0], [0, 1]]) hull = [1](points)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect casing or misspelled class names
Trying to call a function that does not exist
✗ Incorrect
The convex hull object is created by calling ConvexHull(points).
3fill in blank
hardFix the error in accessing the convex hull vertices.
SciPy
import numpy as np from scipy.spatial import ConvexHull points = np.array([[0, 0], [1, 1], [1, 0], [0, 1]]) hull = ConvexHull(points) vertices = hull.[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular 'vertex' instead of 'vertices'
Trying to access non-existent attributes like 'verts'
✗ Incorrect
The convex hull vertices are accessed using hull.vertices.
4fill in blank
hardFill both blanks to create a dictionary of hull vertices and their coordinates.
SciPy
vertex_coords = {hull.[1][i]: points[hull.[2][i]] for i in range(len(hull.vertices))} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different or incorrect attribute names for the two blanks
Using singular 'vertex' instead of 'vertices'
✗ Incorrect
Both blanks should be vertices to access the indices of hull vertices.
5fill in blank
hardFill all three blanks to compute the perimeter of the convex hull polygon.
SciPy
import numpy as np perimeter = 0 for i in range(len(hull.[1])): start = points[hull.[2][i]] end = points[hull.[3][(i + 1) % len(hull.vertices)]] perimeter += np.linalg.norm(end - start)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'points' instead of 'vertices' in the blanks
Not using modulo to wrap around the last vertex
✗ Incorrect
All blanks should be vertices to iterate over the hull vertex indices and compute distances between consecutive points.