仅需6道题轻松掌握SciPy空间计算基础 | Python技能树征题
2021/10/16 12:39:19
本文主要是介绍仅需6道题轻松掌握SciPy空间计算基础 | Python技能树征题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
仅需6道题轻松掌握SciPy空间计算基础 | Python技能树征题
- 0. 前言
- 1. 第 1 题:三角剖分
- 2. 第 2 题:凸包
- 3. 第 3 题:K-D树
- 4. 第 4 题:曼哈顿距离
- 5. 第 5 题:余弦距离
- 6. 第 6 题:汉明距离
- 试题代码地址
0. 前言
空间计算探讨利用空间原则计算的原理和方法处理空间数据,其中空间计算是指在几何空间中表示的数据,我们需要在许多任务中处理空间问题,例如计算空间中两点间的距离,我们就通过 6
道 Python SciPy
编程题来掌握解决基础空间计算问题的方法吧!
1. 第 1 题:三角剖分
知识点描述:多边形的三角剖分可以将多边形划分为多个三角形,这些三角形可用于计算多边形的面积。
问题描述:编写程序从给定点生成的多边形进行三角剖分,请从以下选项中选出你认为正确的答案:
A.
import numpy as np from scipy.spatial import Delaunay import matplotlib.pyplot as plt points = np.array([[2, 4], [3, 4], [3, 0], [2, 2], [4, 1], [5, 5]]) simplices = Delaunay(points).points plt.triplot(points[:, 0], points[:, 1], simplices) plt.scatter(points[:, 0], points[:, 1], color='m') plt.show()
B.
import numpy as np from scipy.spatial import Delaunay import matplotlib.pyplot as plt points = np.array([[2, 4], [3, 4], [3, 0], [2, 2], [4, 1], [5, 5]]) simplices = Delaunay(points).neighbors plt.triplot(points[:, 0], points[:, 1], simplices) plt.scatter(points[:, 0], points[:, 1], color='m') plt.show()
C.
import numpy as np from scipy.spatial import Delaunay import matplotlib.pyplot as plt points = np.array([[2, 4], [3, 4], [3, 0], [2, 2], [4, 1], [5, 5]]) simplices = Delaunay(points).simplices plt.triplot(points[:, 0], points[:, 1], simplices) plt.scatter(points[:, 0], points[:, 1], color='m') plt.show()
D.
import numpy as np from scipy.spatial import Delaunay import matplotlib.pyplot as plt points = np.array([[2, 4], [3, 4], [3, 0], [2, 2], [4, 1], [5, 5]]) simplices = Delaunay(points).coplanar plt.triplot(points[:, 0], points[:, 1], simplices) plt.scatter(points[:, 0], points[:, 1], color='m') plt.show()
正确答案: C
2. 第 2 题:凸包
知识点描述:凸包是覆盖所有给定点的最小凸多边形。
问题描述:已知存在若干给定点,创建能够覆盖这些所有点的最小凸多边形,请从以下选项中选出你认为正确的答案:
A.
import numpy as np from scipy.spatial import ConvexHull import matplotlib.pyplot as plt points = np.array([[2, 4], [3, 4], [3, 0], [2, 2], [4, 1], [5, 5], [6, 7]]) hull_points = ConvexHull(points).points plt.scatter(points[:,0], points[:,1]) for simplex in hull_points: plt.plot(points[simplex,0], points[simplex,1], 'm-') plt.show()
B.
import numpy as np from scipy.spatial import ConvexHull import matplotlib.pyplot as plt points = np.array([[2, 4], [3, 4], [3, 0], [2, 2], [4, 1], [5, 5], [6, 7]]) hull_points = ConvexHull(points).simplices plt.scatter(points[:,0], points[:,1]) for simplex in hull_points: plt.plot(points[simplex,0], points[simplex,1], 'm-') plt.show()
C.
import numpy as np from scipy.spatial import ConvexHull import matplotlib.pyplot as plt points = np.array([[2, 4], [3, 4], [3, 0], [2, 2], [4, 1], [5, 5], [6, 7]]) hull_points = ConvexHull(points).neighbors plt.scatter(points[:,0], points[:,1]) for simplex in hull_points: plt.plot(points[simplex,0], points[simplex,1], 'm-') plt.show()
D.
import numpy as np from scipy.spatial import ConvexHull import matplotlib.pyplot as plt points = np.array([[2, 4], [3, 4], [3, 0], [2, 2], [4, 1], [5, 5], [6, 7]]) hull_points = ConvexHull(points).coplanar plt.scatter(points[:,0], points[:,1]) for simplex in hull_points: plt.plot(points[simplex,0], points[simplex,1], 'm-') plt.show()
正确答案: B
3. 第 3 题:K-D树
知识点描述:K-D树是为最近邻查询而优化的数据结构。
问题描述:使用给定点构造 K-D树,并且根据构造的 K-D树距离查询点 (2, 3) 的最近的点,请从以下选项中选出你认为正确的答案:
A.
from scipy.spatial import KDTree points = [(-2, -1), (3, 8), (-2, 5), (-2, -3)] kdtree = KDTree(points) res = kdtree.query((2, 3)) print(res)
B.
from scipy.spatial import KDTree points = [(-2, -1), (3, 8), (-2, 5), (-2, -3)] kdtree = KDTree(points) res = kdtree.query_ball_point((2, 3)) print(res)
C.
from scipy.spatial import KDTree points = [(-2, -1), (3, 8), (-2, 5), (-2, -3)] kdtree = KDTree(points) res = kdtree.query_pairs((2, 3)) print(res)
D.
from scipy.spatial import KDTree points = [(-2, -1), (3, 8), (-2, 5), (-2, -3)] kdtree = KDTree(points) res = kdtree.query_ball_tree((2, 3)) print(res)
正确答案: A
4. 第 4 题:曼哈顿距离
知识点描述:计算曼哈顿距离,即城市街区距离。
问题描述:查找给定点之间的曼哈顿距离,请从以下选项中选出你认为正确的答案:
A.
from scipy.spatial.distance import euclidean points_1 = (5, 5) points_2 = (10, 10) res = euclidean(points_1, points_2) print(res)
B.
from scipy.spatial.distance import cityblock points_1 = (5, 5) points_2 = (10, 10) res = cityblock(points_1, points_2) print(res)
C.
from scipy.spatial.distance import euclidean points_1 = (5, 5) points_2 = (10, 10) res = euclidean(points_1, points_2) ** 2 print(res)
D.
from scipy.spatial.distance import cityblock points_1 = (5, 5) points_2 = (10, 10) res = cityblock(points_1, points_2) ** 2 print(res)
正确答案: B
5. 第 5 题:余弦距离
知识点描述:余弦距离是两个向量间的夹角的余弦值。
问题描述:求给定点之间的余弦距离,请从以下选项中选出你认为正确的答案:
A.
from scipy.spatial.distance import euclidean points_1 = (5, 5) points_2 = (8, 10) res = euclidean(points_1, points_2) print(res)
B.
from scipy.spatial.distance import euclidean points_1 = (5, 5) points_2 = (8, 10) res = 1 / euclidean(points_1, points_2) print(res)
C.
from scipy.spatial.distance import cosine points_1 = (5, 5) points_2 = (8, 10) res = 1 / cosine(points_1, points_2) print(res)
D.
from scipy.spatial.distance import cosine points_1 = (5, 5) points_2 = (8, 10) res = cosine(points_1, points_2) print(res)
正确答案: D
6. 第 6 题:汉明距离
知识点描述:汉明距离是给定点对应位置中的不同位个数的比例。
问题描述:求给定点之间的汉明距离,请从以下选项中选出你认为正确的答案:
A.
from scipy.spatial.distance import hamming points_1 = (1, 2, 3, 4, 5) points_2 = (1, 3, 4, 4, 5) res = 1 / hamming(points_1, points_2) print(res)
B.
from scipy.spatial.distance import euclidean points_1 = (1, 2, 3, 4, 5) points_2 = (1, 3, 4, 4, 5) res = 1 / euclidean(points_1, points_2) print(res)
C.
from scipy.spatial.distance import hamming points_1 = (1, 2, 3, 4, 5) points_2 = (1, 3, 4, 4, 5) res = hamming(points_1, points_2) print(res)
D.
from scipy.spatial.distance import euclidean points_1 = (1, 2, 3, 4, 5) points_2 = (1, 3, 4, 4, 5) res = euclidean(points_1, points_2) print(res)
正确答案: C
试题代码地址
https://codechina.csdn.net/LOVEmy134611/python_problem
这篇关于仅需6道题轻松掌握SciPy空间计算基础 | Python技能树征题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南
- 2024-11-06Python编程基础入门指南
- 2024-11-06怎么使用python 计算两个GPS的距离功能-icode9专业技术文章分享