0
0
SciPydata~10 mins

Delaunay triangulation 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 Delaunay class from scipy.spatial.

SciPy
from scipy.spatial import [1]

points = [[0, 0], [1, 0], [0, 1]]
delaunay = Delaunay(points)
Drag options to blanks, or click blank then click option'
ADelaunay
BVoronoi
CKDTree
DConvexHull
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Voronoi instead of Delaunay
Using ConvexHull which is for convex shapes, not triangulation
Forgetting to import from scipy.spatial
2fill in blank
medium

Complete the code to create a Delaunay triangulation object from the points array.

SciPy
import numpy as np
from scipy.spatial import Delaunay

points = np.array([[0, 0], [1, 0], [0, 1], [1, 1]])
delaunay = [1](points)
Drag options to blanks, or click blank then click option'
AKDTree
BVoronoi
CConvexHull
DDelaunay
Attempts:
3 left
💡 Hint
Common Mistakes
Using ConvexHull or Voronoi instead of Delaunay
Passing points incorrectly as a list instead of numpy array
3fill in blank
hard

Fix the error in accessing the indices of the simplices (triangles) from the Delaunay object.

SciPy
import numpy as np
from scipy.spatial import Delaunay

points = np.array([[0, 0], [1, 0], [0, 1], [1, 1]])
delaunay = Delaunay(points)
triangles = delaunay.[1]
Drag options to blanks, or click blank then click option'
Asimplices
Bvertices
Ctriangles
Dindices
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'vertices' which is deprecated
Trying to access 'triangles' which does not exist
Using 'indices' which is not an attribute
4fill in blank
hard

Fill both blanks to create a dictionary that maps each point to the number of triangles it belongs to.

SciPy
triangle_counts = {point: 0 for point in range(len(points))}
for triangle in delaunay.[1]:
    for vertex in triangle:
        triangle_counts[[2]] += 1
Drag options to blanks, or click blank then click option'
Asimplices
Bvertex
Ctriangle
Dpoints
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'vertices' instead of 'vertex' in the inner loop
Using 'triangle' instead of 'vertex' to index the dictionary
Using 'points' which is the array, not the index
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each point to the number of triangles it belongs to.

SciPy
triangle_counts = [1]: sum(1 for triangle in delaunay.[2] if [1] in triangle) for [1] in range(len(points))}
Drag options to blanks, or click blank then click option'
Apoint
Bsimplices
Dvertex
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently
Using 'vertex' instead of 'point' in the comprehension
Using wrong attribute instead of 'simplices'