Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Ian Mallett
Using http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html, I came up with: x0 = numpy.array(#point to collide with) x1 = #objects' positions x2 = #objects' previous positions numerator = numpy.sqrt((numpy.cross((x0-x1),(x0-x2))**2).sum(1)) denominator = numpy.sqrt(((x2-x1)**2).sum(1))

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Ian Mallett
It was in an error code somewhere. I fixed the problem by messing around with it. I tried the following: a = numpy.array([1, 2, 3]) print a and it gave: [1, 2, 3] instead of: array([1, 2, 3]) Then there were errors about it being a sequence instead of an array somewhere else. Ian

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Eric Firing
Ian Mallett wrote: > Yeah, I ended up finding the [0] bit at the end through trial and > error. I actually do need the indices, though. If you are not already doing so, I strongly recommend using ipython. It is enormously useful in accessing docstrings (type a function name followed by a qu

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Charles R Harris
On Sun, Apr 26, 2009 at 3:32 PM, Ian Mallett wrote: > Yes, this is pretty much what I'm doing. Right now, I'm having weird > troubles with the objects themselves; the objects should and do terminate > after a certain time, yet for some reason they're still being drawn. User > error, I'm sure. >

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Ian Mallett
On Sat, Apr 25, 2009 at 1:26 PM, Ian Mallett wrote: > I'm going to guess SciPy might be faster (?), but unfortunately it's not > going to be available. Thanks, though. > ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Ian Mallett
The problem is that the object moves too much between frames. A reasonable bounding sphere is 1 for this purpose, but the objects move at least 3. So, given the two arrays, one holding the objects' positions and the other their previous positions, how can I find if, at some point between, the obj

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Ian Mallett
Yes, this is pretty much what I'm doing. Right now, I'm having weird troubles with the objects themselves; the objects should and do terminate after a certain time, yet for some reason they're still being drawn. User error, I'm sure. Thanks, Ian ___ Num

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Eike Welk
Hello Ian! On Saturday 25 April 2009, Ian Mallett wrote: > 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 w

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Ian Mallett
Hmmm, I played around with some other code, and it's working right now--not sure what I did... ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Ian Mallett
Yeah, I ended up finding the [0] bit at the end through trial and error. I actually do need the indices, though. I'm having a strange new problem though. numpy.array([1,2,3]) is returning a sequence??? I'm really confused. Ian ___ Numpy-discussion mai

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Eric Firing
Ian Mallett wrote: > It would be: > numpy.where(array right? Almost. where(cond) is equivalent to nonzero(cond), and both return tuples. Assuming your array is 1-D, you can use: numpy.where(arrayhttp://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Ian Mallett
It would be: numpy.where(array___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] Distance Formula on an Array

2009-04-26 Thread Ian Mallett
Well, if it will kill performance, I'm afraid I can't do that. Thanks though. I think it's working now. Now that I have the 1D array of distances, I need the indices of those distances that are less than a number "d". what should I do to do that? Thanks, Ian ___