MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: comparing two lists

  • To: mathgroup at
  • Subject: [mg54321] Re: [mg54284] comparing two lists
  • From: "David Park" <djmp at>
  • Date: Thu, 17 Feb 2005 10:30:41 -0500 (EST)
  • Sender: owner-wri-mathgroup at


Here is one solution. You will probably get better.

rowPositions[mat_?MatrixQ, vec_?VectorQ] /;
    First[Dimensions[mat]] == Length[vec] :=
  Module[{row, element},
    Table[row = Part[mat, i]; element = Part[vec, i];
      If[Part[row, j] > element, Part[Position[row, Part[row, j]], 1, 1],
        Unevaluated[Sequence[]]], {i, 1, Length[vec]}, {j, 1,

vec = Table[Random[], {2}]
{0.688775, 0.554987}

mat = Table[Table[Random[], {4}], {2}]
{{0.768502, 0.993643, 0.474089, 0.328082}, {0.0175592, 0.671364, 0.461452,

rowPositions[mat, vec]
{{1, 2}, {2}}

David Park
djmp at

From: Curt Fischer [mailto:tentrillion at]
To: mathgroup at

Dear Group:

I want to write a function that accepts a n-vector and an n x m matrix.
It should return a list of positions in the matrix where mat[[i,j]] >
vec[[i]].  For example,





I would like myFunc[] to return {{2},{1,2,3}}.

How could I write this as a pure function?  Ideally I would like to be
able to Map or Apply my function to the list {mat, vec} and get my result.

Something like


is doomed to fail because the PatternTest required in Position[] messes
up the slotting of the other arguments.

Ideas?  How do you nest pure functions?

Curt Fischer

  • Prev by Date: Re: comparing two lists
  • Next by Date: Re: Re: Bug Report - Two numerical values for a same variable
  • Previous by thread: Re: comparing two lists
  • Next by thread: FW: comparing two lists