The points at indices 0,1,2,3 form the square boundary; point 4 is inside.
Step 2: Understand hull.vertices output
hull.vertices returns indices of points forming the hull boundary, excluding interior points.
Final Answer:
[0 1 2 3] -> Option D
Quick Check:
Vertices exclude inside points = [0 1 2 3] [OK]
Hint: Hull vertices exclude points inside the shape [OK]
Common Mistakes:
Including interior points in hull vertices
Expecting all points as hull vertices
Misunderstanding output as coordinates instead of indices
4. The following code throws an error. What is the likely cause?
import numpy as np
from scipy.spatial import ConvexHull
points = np.array([[0, 0], [1, 1]])
hull = ConvexHull(points)
print(hull.vertices)
medium
A. Missing import statement
B. Points are not in ascending order
C. Not enough points to form a convex hull
D. Points array has wrong data type
Solution
Step 1: Check minimum points needed for convex hull
Convex hull in 2D requires at least 3 points to form a polygon.
Step 2: Analyze given points
Only 2 points are given, so ConvexHull cannot compute a polygon, causing an error.
Final Answer:
Not enough points to form a convex hull -> Option C
Quick Check:
Minimum 3 points needed for 2D hull [OK]
Hint: Convex hull needs at least 3 points in 2D [OK]
Common Mistakes:
Assuming any number of points works
Thinking order of points matters for hull computation
Ignoring error message about input size
5. You have a set of 2D points representing city locations. You want to find the smallest fence enclosing all cities. Which steps correctly use scipy.spatial.ConvexHull to find the fence points?
hard
A. Import ConvexHull, sort points by x-coordinate, use hull.simplices to get fence points
B. Import ConvexHull, create numpy array of points, compute hull, use hull.vertices to get fence points
C. Import ConvexHull, compute hull, use hull.area to get fence points
D. Import ConvexHull, compute hull, use hull.points to get fence points
Solution
Step 1: Prepare data and compute hull
Import ConvexHull, convert city coordinates to numpy array, then compute hull = ConvexHull(points).
Step 2: Extract fence points using hull.vertices
hull.vertices gives indices of points forming the convex hull boundary (fence).
Final Answer:
Import ConvexHull, create numpy array of points, compute hull, use hull.vertices to get fence points -> Option B
Quick Check:
hull.vertices = fence points [OK]
Hint: Use hull.vertices for boundary points, not hull.area or hull.points [OK]
Common Mistakes:
Using hull.area which is a number, not points
Using hull.points which is all points, not boundary
Sorting points manually instead of using hull.vertices
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.