python删除数组中重复的数字_python – 从Numpy向量数组中删除重复项(在给定的容差范围内)...

你可能会看一下

scipy.spatial.KDTree.

N有多大?

补充:oops,tree.query_pairs不是scipy 0.7.1.

如有疑问,请使用蛮力:将空间(此处为^ 3)分成小单元格,

每个单元一个点:

""" scatter points to little cells, 1 per cell """

from __future__ import division

import sys

import numpy as np

side = 100

npercell = 1 # 1: ~ 1/e empty

exec "\n".join( sys.argv[1:] ) # side= ...

N = side**3 * npercell

print "side: %d npercell: %d N: %d" % (side, npercell, N)

np.random.seed( 1 )

points = np.random.uniform( 0, side, size=(N,3) )

cells = np.zeros( (side,side,side), dtype=np.uint )

id = 1

for p in points.astype(int):

cells[tuple(p)] = id

id += 1

cells = cells.flatten()

# A C, an E-flat, and a G walk into a bar.

# The bartender says, "Sorry, but we don't serve minors."

nz = np.nonzero(cells)[0]

print "%d cells have points" % len(nz)

print "first few ids:", cells[nz][:10]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值