Re: [Numpy-discussion] Lookup array
В Mon, 10 Oct 2011 11:20:08 -0400 Olivier Delalleau sh...@keba.be пишет: The following doesn't use numpy but seems to be about 20x faster: A_rows = {} for i, row in enumerate(A): A_rows[tuple(row)] = i for i, row in enumerate(B): C[i] = A_rows.get(tuple(row), -1) -=- Olivier Thanks a lot, Olivier, that's makes my program like 3x faster. One lesson I can draw from this - don't try to use NumPy in situations it doesn't fit :) WBR, Andrey -- Researcher, General and theoretical physics dept., South Ural State University 454080, Pr. Lenina, 76, Chelyabinsk, Russia Tel: +7 351 265-47-13 and...@physics.susu.ac.ru ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Norm of array of vectors
Dear all, Sorry if that's a noob question, but anyway. I have several thousands of vectors stacked in 2d array. I'd like to get new array containing Euclidean norms of these vectors and get the vector with minimal norm. Is there more efficient way to do this than argmin(array([sqrt(dot(x,x)) for x in vec_array]))? Thanks in advance. Andrey. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Norm of array of vectors
Hi eat and Gary, Thanks a lot for your suggestions, I've tried them in my code and achieved similar speedup of ~270% for both of them. So I guess I'll stick to one of those. Regards, Andrey. Hi, On Thu, Mar 17, 2011 at 10:44 AM, Andrey N. Sobolev inco...@list.ru wrote: Dear all, Sorry if that's a noob question, but anyway. I have several thousands of vectors stacked in 2d array. I'd like to get new array containing Euclidean norms of these vectors and get the vector with minimal norm. Is there more efficient way to do this than argmin(array([sqrt(dot(x,x)) for x in vec_array]))? Try argmin(sum(vec_array** 2, 0)** 0.5) Regards, eat Thanks in advance. Andrey. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion