"Andy Cheesman" <[EMAIL PROTECTED]> wrote > I'm trying to match a row (b) within a large numpy array (a). My > most > successful attempt is below
I'm nonumpy expert but... > hit = equal(b, a) > total_hits = add.reduce(hit, 1) > max_hit = argmax(total_hits, 0) > answer = a[max_hit] Where are all of these functions coming from? Are they numpy? (I couldn't find them on the reference at: http://www.hjcb.nl/python/Arrays.html) Their function is not intuitively obvious to me. For example, why does "equal" take a row and an array - would an array ever be equal to a row or vice versa? (Unless the array only had one row, I suppose?) And what is add.reduce? Is it related to the standard reduce? - the prototype is different... Even argmax is not totally clear, how does it differ from normal max()? In other words I'm not sure what the steps are doing so can't suggest much improvement. Maybe other > 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 > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor