| Original Message (ID '71607') By Peter Pein: |
| Hi Tatjana,
there is no need to use a nested loop.
The following gives you the maximal absolute value and a list of positions where these elements are located in the matrix:
In[7]:= A = RandomInteger[{-5, 5}, {4, 4}]
Out[7]= {{-5, 1, 3, -5},
{-2, 2, 5, 5},
{-5, 3, 2, -3},
{-4, 1, 0, 1}}
In[8]:= Block[{abs = Abs[A], max},
{max = Max[Flatten[abs]], Position[abs, max]}]
Out[8]= {5, {{1, 1}, {1, 4}, {2, 3}, {2, 4}, {3, 1}}}
Peter
|
|