[Numpy-discussion] Distance Formula on an Array
Ian Mallett
geometrian@gmail....
Sat Apr 25 15:26:25 CDT 2009
On Sat, Apr 25, 2009 at 12:57 PM, Charles R Harris <
charlesr.harris@gmail.com> wrote:
> In [3]: vec = array([[0,0,0],[0,1,0],[0,0,3]])
>
> In [4]: pos = array([0,4,0])
>
> In [5]: sqrt(((vec - pos)**2).sum(1))
> Out[5]: array([ 4., 3., 5.])
>
> Chuck
>
On Sat, Apr 25, 2009 at 1:00 PM, <josef.pktd@gmail.com> wrote:
> if scipy is permitted:
>
> >>> a = np.array([[0,0,0],[0,1,0],[0,0,3]])
> >>> scipy.spatial.distance_matrix(a, [[0,4,0]])
> array([[ 4.],
> [ 3.],
> [ 5.]])
> >>> scipy.spatial.minkowski_distance(a, [0,4,0])
> array([ 4., 3., 5.])
>
> Josef
Thanks you two. I'm going to guess SciPy might be faster (?), but
unfortunately it's not going to be available. Thanks, though. Problem
solved.
Thanks again,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090425/07f7b7f6/attachment.html
More information about the Numpy-discussion
mailing list