[Numpy-discussion] Distance Formula on an Array

Ian Mallett geometrian at gmail.com
Sat Apr 25 16:38:13 EDT 2009


Oops, one more thing.  In reference to:
vec = array([[0,0,0],[0,1,0],[0,0,3]])
pos = array([0,4,0])
sqrt(((vec - pos)**2).sum(1)) -> array([ 4.,  3.,  5.])

Can I make "vec" an array of class instances?  I tried:
class c:
    def __init__(self):
        self.position = [0,0,0]
vec = array([c(),c(),c()])
pos = array([0,4,0])
sqrt(((vec.position - pos)**2).sum(1))

Which doesn't work.  I'm not familiar with class objects in arrays--how
should they be referenced?

Thanks again,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090425/25841ba3/attachment.html>


More information about the NumPy-Discussion mailing list