# [SciPy-user] getting rid of for loops...

Emanuele Zattin emanuelez@gmail....
Fri Aug 3 03:43:03 CDT 2007

```Very nice indeed.
My approach was different (big 2D arrays), but this one looks way more
elegant and probably even faster (the performancedifference from the
double for loop and my solution was already impressive)

On 8/3/07, Niels L. Ellegaard <niels.ellegaard@gmail.com> wrote:
> 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?
>
>
>                Niels
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>

--
Emanuele Zattin
---------------------------------------------------
-I don't have to know an answer. I don't feel frightened by not
knowing things; by being lost in a mysterious universe without any
purpose — which is the way it really is, as far as I can tell,
possibly. It doesn't frighten me.- Richard Feynman
```