Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7063641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:44:14+00:00 2026-05-28T04:44:14+00:00

This question is a continuation of a previous thread to compare two lists with

  • 0

This question is a continuation of a previous thread to compare two lists with the same length:

Is there any efficient easy way to compare two lists with the same length with Mathematica?

Given two lists A={a1,a2,a3,...an} and B={b1,b2,b3,...bn}, I would say A>=B if and only if all ai>=bi. Now we have k lists H={{a11,a12,a13,...a1n}, {a21,a22,a23,...a2n},...,{ak1,ak2,ak3,...akn}}, and want to find the maximum one if exist.

Here’s my code:

Do[If[NonNegative[Min[H[[i]] - h]], h = H[[i]], ## &[]], {i, h = H[[1]]; 1, Length[H]}];h

Any better trick to do this?

EDIT:

I want to define this as a function like:

maxList[H_]:=Do[If[NonNegative[Min[H[[i]] - h]], h = H[[i]], ## &[]], {i, h = H[[1]]; 1, Length[H]}];h

But the question is the code above cross two lines, any fix for this? Here is some code working but not that beautiful

maxList[H_] := Module[{h = H[[1]]}, Do[If[NonNegative[Min[H[[i]] - h]], h = H[[i]], ## &[]], {i, Length[H]}]; h]

or

maxList[H_]:=Last[Table[If[NonNegative[Min[H[[i]] - h]], h = H[[i]], ## &[]], {i, h = H[[1]]; 1, Length[H]}]]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:44:15+00:00Added an answer on May 28, 2026 at 4:44 am

    A modification of Mr.Wizard’s approach works a few times faster.

    maxListFast[list_List] := Module[{l}, 
                                     l = Max /@ Transpose@list; 
                                     If[MemberQ[list, l], l, {}]]
    

    We test the both methods with

    test  = RandomInteger[100, {500000, 10}];
    test1 = Insert[test, Table[100, {10}], RandomInteger[{1, 500000}]]; 
    

    and we get

    In[5]:= maxList[test] // Timing
            maxListFast[test] // Timing
    
            Out[5]= {2.761, {}}
            Out[6]= {0.265, {}}
    

    and

    In[7]:= maxList[test1] // Timing
            maxListFast[test1] // Timing
    
    Out[7]= {1.217, {{100, 100, 100, 100, 100, 100, 100, 100, 100, 100}}}
    Out[8]= {0.14, {100, 100, 100, 100, 100, 100, 100, 100, 100, 100}}
    

    EDIT

    In general, to choose a method, we should know first what kind of data we are to deal with. (lenght of lists, their number, types of numbers ). While we have a large number of short lists
    of integers maxListFast works even 10 times better (in case of 500000 lists of length 10) than maxList.
    However for lists of real numbers it is only 3-4 times faster, and the more and the longer list we have the more it slows down, e.g. :

             A = RandomReal[1000, {3000, 3000}];
             First@AbsoluteTiming[maxListFast@A;]/ First@AbsoluteTiming[maxList@A;]
    
    Out[19]= 2.040516    
    

    however if we insert “the greatest element” :

    In[21]:= IA = Insert[A, Table[1000, {3000}], RandomInteger[{1, 3000}]];
    In[22]:= First@AbsoluteTiming[maxListFast@IA;]/ First@AbsoluteTiming[maxList@IA;]
    
    Out[22]= 0.9781931
    

    timings close up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is a continuation of my previous question is there off-the-shelf convenient way to
This question is in continuation to my previous post located here . Since there
This question is a continuation of my previous question here zend models architecture (big
This is a continuation question from a previous question I have asked I now
This question is in continuation to my previous question, in which I asked about
This is a continuation from a previous stackoverflow question. I've renamed some variables so
This is in continuation to my previous question which was closed cause of similarity
This is a continuation of my previous question which I posted when I wasn't
This question is a continuation of this thread : In short: To solve my
This is a continuation of my previous question: Could not find an implementation of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.