【发布时间】:2018-03-16 05:54:50
【问题描述】:
我想将数组“a”(如下所示)排序(从最短到最长)到距原点或点(在我的情况下为 0,0)的距离,并将其存储到类似的数组类型“b”中' 或替换数组 'a'
以下给定点是 3d numpy 数组
[[[ 510. 11.]]
[[ 651. 276.]]
[[ 269. 70.]]
[[ 920. 26.]]
[[ 513. 21.]]
[[ 1197. 620.]]
[[ 407. 268.]]
[[ 452. 35.]]
[[ 435. 3.]]
[[ 520. 20.]]
[[ 1151. 499.]]
[[ 104. 26.]]
[[ 754. 28.]]
[[ 263. 111.]]
[[ 731. 12.]]
[[ 972. 200.]]
[[ 1186. 614.]]
[[ 437. 2.]]
[[ 1096. 68.]]
[[ 997. 201.]]
[[ 1087. 200.]]
[[ 913. 201.]]
[[ 1156. 510.]]
[[ 994. 230.]]
[[ 793. 29.]]
[[ 514. 19.]]]
我找不到任何有关此类 3d np 数组排序的有用信息
ps:这些点 'a' 是从 Goodfeaturestotrack 、OPEN CV 、python 3.6 获得的
以及如何将数组清除为 Null 类型?
#this is clustering algorithm
for index in range(len(a): #a is the above matrix 3d np array
#find distance was already defined and is euclidean distance formula
if findDistance(a[index][0], a[index][1], a[index + 1][0], a[index + 1][1]) < 3: #calculation euclidean distance between ai and ai+1
c.append(index)
if findDistance(a[index][0], a[index][1], a[index + 1][0], a[index + 1][1]) > 3: #calculation euclidean distance between ai and ai+1
if len(c) > 10:
cp = np.insert(cp, c, 0)
c = [] # should clear c **is this correct ??**
【问题讨论】:
-
和
del c[:]将删除 c 中的所有内容,而不是c= [] -
谢谢!
cp=np.insert(cp,c,0)这是将 c 数组复制到 cp 的正确方法吗? -
insert 将新列添加到数组中,但不会覆盖原始数组。 Numpy 实际上在他们的网站上有很好的文档和示例
-
肯定会检查出来的!
标签: python arrays sorting numpy opencv3.0