[SciPy-user] getting rid of for loops...
Niels L. Ellegaard
niels.ellegaard@gmail....
Fri Aug 3 03:28:07 CDT 2007
LB <berthe.loic@gmail.com> writes:
> Suppose you want to compare two matrices A and B :
>>>> A = random.randint(-10, 10, size=(4, 5))
>>>> B = random.randint(-10, 10, size=(6, 5))
>>>> tolerance = array([10, 15, 5, 8, 6])
>>>> data1= A[newaxis, :, :]
>>>> data2 = B[:, newaxis, :]
>>>> close_enough = less(abs( data1-data2), tolerance).all(axis=2)
Wow, that was a nice trick and a useful example. Would it make
sense to add it as example 6 to the broadcasting wiki page?
http://www.scipy.org/EricsBroadcastingDoc
Niels
More information about the SciPy-user
mailing list