[Numpy-discussion] Finding a row match within a numpy array

Matthieu Brucher matthieu.brucher at gmail.com
Wed Aug 15 07:38:14 EDT 2007


The where function ?

Matthieu

2007/8/15, mark <markbak at gmail.com>:
>
> Oops, 'find' is in pylab (matplotlib).
> I guess in numpy you have to use 'where', which does almost the same,
> but it returns a Tuple.
> Is there a function that is more like the find in matplotlib?
> Mark
>
>
> On Aug 15, 12:26 pm, Andy Cheesman <Andy.chees... at bristol.ac.uk>
> wrote:
> > Thanks for the speedy response but where can I locate the find function
> > as it isn't in numpy.
> >
> > Andy
> >
> >
> >
> > mark wrote:
> > > I think you can create an array with a true value in the right spot as
> > > folows:
> >
> > > row = all( equal(a,b), 1 )
> >
> > > Then you can either find the row (but you already knew that one, as it
> > > is b)
> >
> > > a[row]
> >
> > > or the row index
> >
> > > find(row==True)
> >
> > > Mark
> >
> > > On Aug 15, 11:53 am, Andy Cheesman <Andy.chees... at bristol.ac.uk>
> > > wrote:
> > >> Dear nice people
> >
> > >> I'm trying to match a row (b) within a large numpy array (a). My most
> > >> successful attempt is below
> >
> > >> hit = equal(b, a)
> > >> total_hits = add.reduce(hit, 1)
> > >> max_hit = argmax(total_hits, 0)
> > >> answer = a[max_hit]
> >
> > >> where ...
> > >> a = array([[ 0,  1,  2,  3],
> > >>            [ 4,  5,  6,  7],
> > >>            [ 8,  9, 10, 11],
> > >>            [12, 13, 14, 15]])
> >
> > >> b = array([8,  9, 10, 11])
> >
> > >> I was wondering if people could suggest a possible more efficient
> route
> > >> as there seems to be numerous steps.
> >
> > >> Thanks
> > >> Andy
> > >> _______________________________________________
> > >> Numpy-discussion mailing list
> > >> Numpy-discuss... at scipy
> .orghttp://projects.scipy.org/mailman/listinfo/numpy-discussion
> >
> > > _______________________________________________
> > > Numpy-discussion mailing list
> > > Numpy-discuss... at scipy.org
> > >http://projects.scipy.org/mailman/listinfo/numpy-discussion
> >
> > _______________________________________________
> > Numpy-discussion mailing list
> > Numpy-discuss... at scipy
> .orghttp://projects.scipy.org/mailman/listinfo/numpy-discussion
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070815/12eb315c/attachment.html>


More information about the NumPy-Discussion mailing list