Challenge - 5 Problems
Convex Hull Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Convex Hull vertices indices
What is the output of this code snippet that computes the convex hull of a set of 2D points using scipy?
SciPy
import numpy as np from scipy.spatial import ConvexHull points = np.array([[0, 0], [1, 1], [1, 0], [0, 1], [0.5, 0.5]]) hull = ConvexHull(points) print(list(hull.vertices))
Attempts:
2 left
💡 Hint
The convex hull vertices are the outermost points forming the polygon around all points.
✗ Incorrect
The points at indices 0, 2, 1, and 3 form the convex polygon enclosing all points. The point at index 4 lies inside and is not part of the hull vertices.
❓ data_output
intermediate2:00remaining
Number of simplices in 3D convex hull
Given a set of 3D points, how many simplices (triangular faces) does the convex hull have?
SciPy
import numpy as np from scipy.spatial import ConvexHull points = np.random.rand(10, 3) hull = ConvexHull(points) print(len(hull.simplices))
Attempts:
2 left
💡 Hint
The number of simplices depends on the shape formed by the points, but for 10 random points in 3D, it is usually around 16.
✗ Incorrect
For 10 random points in 3D, the convex hull typically has 16 triangular faces (simplices).
🔧 Debug
advanced2:00remaining
Identify the error in convex hull computation
What error does this code raise when trying to compute the convex hull of a single point?
SciPy
import numpy as np from scipy.spatial import ConvexHull points = np.array([[0, 0]]) hull = ConvexHull(points)
Attempts:
2 left
💡 Hint
Convex hull requires at least 3 points in 2D to form a polygon.
✗ Incorrect
The ConvexHull function raises a QhullError because the input has fewer than 3 points, which is insufficient to form a hull in 2D.
❓ visualization
advanced2:00remaining
Visualizing convex hull edges in 2D
Which option correctly plots the convex hull edges for a set of 2D points using matplotlib and scipy?
SciPy
import numpy as np import matplotlib.pyplot as plt from scipy.spatial import ConvexHull points = np.random.rand(15, 2) hull = ConvexHull(points) plt.plot(points[:,0], points[:,1], 'o') for simplex in hull.simplices: plt.plot(points[simplex, 0], points[simplex, 1], 'r-') plt.show()
Attempts:
2 left
💡 Hint
The hull.simplices attribute contains pairs of indices for edges of the hull.
✗ Incorrect
The code plots the points and draws red lines between points that form the convex hull edges, correctly visualizing the hull.
🚀 Application
expert3:00remaining
Using convex hull to filter outliers in 2D data
You have 2D data points with some outliers far from the main cluster. Which approach uses the convex hull to identify and remove outliers?
Attempts:
2 left
💡 Hint
Outliers lie outside the main cluster's convex hull.
✗ Incorrect
To remove outliers, first identify the main cluster, compute its convex hull, and remove points outside this hull. Removing hull vertices or points inside the hull does not remove outliers.