# coding = utf-8
import numpy
as
np
from IPython import embed
# xy 输入,可支持浮点数操作 速度很快哦
#
return
xy 去重后结果
def duplicate_removal(xy):
if
xy.shape[0] < 2:
return
xy
_tmp = (xy*4000).astype(
'i4'
) # 转换成 i4 处理
_tmp = _tmp[:,0] + _tmp[:,1]*1j # 转换成复数处理
keep = np.unique(_tmp, return_index=True)[1] # 去重 得到索引
return
xy[keep] # 得到数据并返回
# _tmp[:,0] 切片操作,因为时二维数组,_tmp[a:b, c:d]为通用表达式,
# 表示取第一维的索引 a 到索引 b,和第二维的索引 c 到索引 d
# 当取所有时可以直接省略,但要加
':'
冒号 、当 a == b 时可只写 a ,同时不用
':'
冒号
if
__name__ ==
'__main__'
:
if
1: # test
xy = np.
array
([[1.0, 1.0, 1.0], [2.0, 2.0, 2.0], [3.0, 0.0, 0.0], [1.0, 1.0, 1.00]])
print
(xy)
new_xy = duplicate_removal(xy)
print
(new_xy)
embed()