[SciPy-user] getting rid of for loops...
Niels L. Ellegaard
Fri Aug 3 03:28:07 CDT 2007
LB <firstname.lastname@example.org> 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?
More information about the SciPy-user