我的函数(名称为CovexHull(point))将参数作为二维数组接受:
hull = ConvexHull(points)
会话
In [1]: points.ndim
Out[1]: 2
In [2]: points.shape
Out[2]: (10, 2)
In [3]: points
Out[3]:
array([[ 0. , 0. ],
[ 1. , 0.8],
[ 0.9, 0.8],
[ 0.9, 0.7],
[ 0.9, 0.6],
[ 0.8, 0.5],
[ 0.8, 0.5],
[ 0.7, 0.5],
[ 0.1, 0. ],
[ 0. , 0. ]])
points是一个具有2个ndim的NumPy数组。
我有两个不同的NumPy数组(tp和fp),如下所示:
In [4]: fp.ndim
Out[4]: 1
In [5]: fp.shape
Out[5]: (10,)
In [6]: fp
Out[6]:
array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.4,
0.5, 0.6, 0.9, 1. ])
我该如何有效地创建一个二维NumPy数组(例如上面提到的points),其中包括tp和fp?
np.column_stack
可以直接获得正确的形状。 - Jaimecolumn_stack
更加直观(参见Aminu的答案)。 - Daniel C Jacobs