Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Minimum of symetrics elements

    Dear all,

    I have a square matrix A, and I'd like to create a matrix W such as : wij = wji = min(aij , aji)
    I've thought about comparing A and A' (because wij also corresponds to min(aij, a'ij) ), but I can't find a way, the minmax functions in Mata only work within a matrix (or rows/colums) and not between two.

    Here is an example :
    Code:
    . mata A =(0,3, 10\ 2, 0, 5\ 1, 1, 0)
    
    . mata A
            1    2    3
        +----------------+
      1 |   0    3   10  |
      2 |   2    0    5  |
      3 |   1    1    0  |
        +----------------+
    
    . mata A'
            1    2    3
        +----------------+
      1 |   0    2    1  |
      2 |   3    0    1  |
      3 |  10    5    0  |
        +----------------+
    I'd like to end up with :
    Code:
    . mata W
    [symmetric]
           1   2   3
        +-------------+
      1 |  0          |
      2 |  2   0      |
      3 |  1   1   0  |
        +-------------+
    Any ideas would be welcome.
    Thanks,
    Charlie

  • #2
    Hi Charlie
    Q&D:
    Code:
    : A =(0,3, 10\ 2, 0, 5\ 1, 1, 0)
    : A :* (A :< A') + A' :* (A' :< A)
    [symmetric]
           1   2   3
        +-------------+
      1 |  0          |
      2 |  2   0      |
      3 |  1   1   0  |
        +-------------+
    This can probably be refined. And I haven't checked it for speed.
    But here it is
    Kind regards

    nhb

    Comment


    • #3
      Many thanks Henrik,
      It works fine, even with a larger matrix of 167x167, so no speed improvement is needed.

      Best,
      Charlie

      Comment

      Working...
      X