0
0
SciPydata~10 mins

Convex hull computation in SciPy - Interactive Code Practice

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

Complete 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'
Ahull
Bconvex_hull
CConvex_Hull
DConvexHull
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or incorrect casing for ConvexHull
Trying to import a non-existent function like convex_hull
2fill in blank
medium

Complete 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'
AHull
Bconvex_hull
CConvexHull
DconvexHull
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect casing or misspelled class names
Trying to call a function that does not exist
3fill in blank
hard

Fix 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'
Apoints
Bvertices
Cvertex
Dverts
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular 'vertex' instead of 'vertices'
Trying to access non-existent attributes like 'verts'
4fill in blank
hard

Fill 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'
Avertices
Bpoints
Cvertex
Dverts
Attempts:
3 left
💡 Hint
Common Mistakes
Using different or incorrect attribute names for the two blanks
Using singular 'vertex' instead of 'vertices'
5fill in blank
hard

Fill 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'
Avertices
Dpoints
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'points' instead of 'vertices' in the blanks
Not using modulo to wrap around the last vertex