Extract the symmetric matrix built-in another matrix

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












Suppose that I have a matrix M:



M=
0,1,1,0,1,0,
1,0,0,1,1,1,
1,1,0,0,1,0,
0,1,1,0,0,0,
1,0,0,1,0,1,
1,1,1,1,0,0
;


I like to extract from M the symmetric matrix symM:



symM=
0, 1, 1, 0, 1, 0,
1, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0
;


I do not want to use Do or If commands. I like to implement matrix operations to extract the symmetric part of M.



EDIT 1



In general terms, matrix M is composed of 1 and 0 only, with the condition that the diagonal cells be zeros. My goal is to extract the matrix symM which should only include 1s in the non-zero reciprocal cells (or symmetric cells), otherwise zero.



Example, in the above example, M[[1,2]]=1 and M[[2,1]]=1, then both symM[[1,2]] and symM[[2,1]] should be 1. All other cells which are not qualified should be all zero.



I hope the question is clearer now. Thank you.










share|improve this question























  • Do you have a particular algorithm in mind?
    – corey979
    4 hours ago










  • @corey979: I do not have any algorithm in mind but maybe Scan can be used to collect the non-negative symmetric positions in M.
    – Tugrul Temel
    4 hours ago






  • 2




    BitAnd[M, Transpose[M]]
    – Coolwater
    2 hours ago










  • @Coolwater That's a good one! Why don't you post it as an answer?
    – Henrik Schumacher
    2 hours ago














up vote
5
down vote

favorite
1












Suppose that I have a matrix M:



M=
0,1,1,0,1,0,
1,0,0,1,1,1,
1,1,0,0,1,0,
0,1,1,0,0,0,
1,0,0,1,0,1,
1,1,1,1,0,0
;


I like to extract from M the symmetric matrix symM:



symM=
0, 1, 1, 0, 1, 0,
1, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0
;


I do not want to use Do or If commands. I like to implement matrix operations to extract the symmetric part of M.



EDIT 1



In general terms, matrix M is composed of 1 and 0 only, with the condition that the diagonal cells be zeros. My goal is to extract the matrix symM which should only include 1s in the non-zero reciprocal cells (or symmetric cells), otherwise zero.



Example, in the above example, M[[1,2]]=1 and M[[2,1]]=1, then both symM[[1,2]] and symM[[2,1]] should be 1. All other cells which are not qualified should be all zero.



I hope the question is clearer now. Thank you.










share|improve this question























  • Do you have a particular algorithm in mind?
    – corey979
    4 hours ago










  • @corey979: I do not have any algorithm in mind but maybe Scan can be used to collect the non-negative symmetric positions in M.
    – Tugrul Temel
    4 hours ago






  • 2




    BitAnd[M, Transpose[M]]
    – Coolwater
    2 hours ago










  • @Coolwater That's a good one! Why don't you post it as an answer?
    – Henrik Schumacher
    2 hours ago












up vote
5
down vote

favorite
1









up vote
5
down vote

favorite
1






1





Suppose that I have a matrix M:



M=
0,1,1,0,1,0,
1,0,0,1,1,1,
1,1,0,0,1,0,
0,1,1,0,0,0,
1,0,0,1,0,1,
1,1,1,1,0,0
;


I like to extract from M the symmetric matrix symM:



symM=
0, 1, 1, 0, 1, 0,
1, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0
;


I do not want to use Do or If commands. I like to implement matrix operations to extract the symmetric part of M.



EDIT 1



In general terms, matrix M is composed of 1 and 0 only, with the condition that the diagonal cells be zeros. My goal is to extract the matrix symM which should only include 1s in the non-zero reciprocal cells (or symmetric cells), otherwise zero.



Example, in the above example, M[[1,2]]=1 and M[[2,1]]=1, then both symM[[1,2]] and symM[[2,1]] should be 1. All other cells which are not qualified should be all zero.



I hope the question is clearer now. Thank you.










share|improve this question















Suppose that I have a matrix M:



M=
0,1,1,0,1,0,
1,0,0,1,1,1,
1,1,0,0,1,0,
0,1,1,0,0,0,
1,0,0,1,0,1,
1,1,1,1,0,0
;


I like to extract from M the symmetric matrix symM:



symM=
0, 1, 1, 0, 1, 0,
1, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0
;


I do not want to use Do or If commands. I like to implement matrix operations to extract the symmetric part of M.



EDIT 1



In general terms, matrix M is composed of 1 and 0 only, with the condition that the diagonal cells be zeros. My goal is to extract the matrix symM which should only include 1s in the non-zero reciprocal cells (or symmetric cells), otherwise zero.



Example, in the above example, M[[1,2]]=1 and M[[2,1]]=1, then both symM[[1,2]] and symM[[2,1]] should be 1. All other cells which are not qualified should be all zero.



I hope the question is clearer now. Thank you.







matrix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 11 mins ago









kglr

168k8191394




168k8191394










asked 4 hours ago









Tugrul Temel

602113




602113











  • Do you have a particular algorithm in mind?
    – corey979
    4 hours ago










  • @corey979: I do not have any algorithm in mind but maybe Scan can be used to collect the non-negative symmetric positions in M.
    – Tugrul Temel
    4 hours ago






  • 2




    BitAnd[M, Transpose[M]]
    – Coolwater
    2 hours ago










  • @Coolwater That's a good one! Why don't you post it as an answer?
    – Henrik Schumacher
    2 hours ago
















  • Do you have a particular algorithm in mind?
    – corey979
    4 hours ago










  • @corey979: I do not have any algorithm in mind but maybe Scan can be used to collect the non-negative symmetric positions in M.
    – Tugrul Temel
    4 hours ago






  • 2




    BitAnd[M, Transpose[M]]
    – Coolwater
    2 hours ago










  • @Coolwater That's a good one! Why don't you post it as an answer?
    – Henrik Schumacher
    2 hours ago















Do you have a particular algorithm in mind?
– corey979
4 hours ago




Do you have a particular algorithm in mind?
– corey979
4 hours ago












@corey979: I do not have any algorithm in mind but maybe Scan can be used to collect the non-negative symmetric positions in M.
– Tugrul Temel
4 hours ago




@corey979: I do not have any algorithm in mind but maybe Scan can be used to collect the non-negative symmetric positions in M.
– Tugrul Temel
4 hours ago




2




2




BitAnd[M, Transpose[M]]
– Coolwater
2 hours ago




BitAnd[M, Transpose[M]]
– Coolwater
2 hours ago












@Coolwater That's a good one! Why don't you post it as an answer?
– Henrik Schumacher
2 hours ago




@Coolwater That's a good one! Why don't you post it as an answer?
– Henrik Schumacher
2 hours ago










3 Answers
3






active

oldest

votes

















up vote
2
down vote



accepted










Maybe this is what you are looking for. I interpreted your question as if you want to replace all nonsymmetric entries of the input matrix by zeroes and as if the input matrix is not necessarily binary.



A = M Subtract[1, Unitize[Subtract[Transpose[M], M]]];





share|improve this answer






















  • Yes...That is what I wanted to have. Perfect...
    – Tugrul Temel
    4 hours ago






  • 1




    @HenrikSchumacher For the symmetric part of M I would have expected something like (M+Transpose[M])/2...Interestingly your result fullfills A==Floor[(M+Transpose[M])/2] !
    – Ulrich Neumann
    4 hours ago






  • 1




    @UlrichNeumann (M+Transpose[M])/2 is the symmetrized part, and in particular the orthogonal projection onto the linear space of symmetric matrices (orthogonal with respect to the Frobenius metric). But as by OP's examples, this was not what the OP asked for.
    – Henrik Schumacher
    4 hours ago










  • @Henrik: Referring to your last point, you are right that your code gives me what I wanted. I checked it with other examples and it works.
    – Tugrul Temel
    4 hours ago

















up vote
5
down vote













Maybe a bit simpler:



M Transpose[M]


Comparing with Henrik's answer:



M Subtract[1, Unitize[Subtract[Transpose[M], M]]] == M Transpose[M]
True





share|improve this answer




















  • Simpler indeed. But it will work only for binary matrices. Well, actually, it is still somewhat unclear, what the OP's usage spectrum and desired result in the general case is supposed to be. I interpreted it as if the OP wants to replace all nonsymmetric entries of the input matrix by zeroes.
    – Henrik Schumacher
    3 hours ago










  • @Henrik -- Agreed, I took the binary example suggested by the OP as indicating interest only in binary matrices.
    – bill s
    3 hours ago











  • @Henrik: I wanted to extract binary cells only: that is, if (i,j)==(j,i)==1, then keep them in the output matrix, otherwise place zeros to both cells. What you are saying in your comment is what I actually wanted: replace all non-symmetric entries of the input matrix with zeros. Is Bill's proposal equivalent to your proposal? I want to make sure this because in the original case with n=1000 I cannot check it visually.
    – Tugrul Temel
    2 hours ago






  • 1




    A simple example for which bill's and my proposals lead to different output is the matrix M = 1, 2,1,1. In general it is preferrable to post also all assumptions on the input data already in the question. Moreover your question leave a lot room for interpretation. Please specify exactly what the desired output for a general input matrix should be.
    – Henrik Schumacher
    2 hours ago











  • @Henrik: I will edit the question in line with your comment.
    – Tugrul Temel
    1 hour ago

















up vote
1
down vote













A = Floor @ Symmetrize @ M;

TeXForm @ MatrixForm @ A



$left(
beginarraycccccc
0 & 1 & 1 & 0 & 1 & 0 \
1 & 0 & 0 & 1 & 0 & 1 \
1 & 0 & 0 & 0 & 0 & 0 \
0 & 1 & 0 & 0 & 0 & 0 \
1 & 0 & 0 & 0 & 0 & 0 \
0 & 1 & 0 & 0 & 0 & 0 \
endarray
right)$




Note: This is much slower than the methods in the answers by bill s and Henrik Schumacher.






share|improve this answer






















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184809%2fextract-the-symmetric-matrix-built-in-another-matrix%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    Maybe this is what you are looking for. I interpreted your question as if you want to replace all nonsymmetric entries of the input matrix by zeroes and as if the input matrix is not necessarily binary.



    A = M Subtract[1, Unitize[Subtract[Transpose[M], M]]];





    share|improve this answer






















    • Yes...That is what I wanted to have. Perfect...
      – Tugrul Temel
      4 hours ago






    • 1




      @HenrikSchumacher For the symmetric part of M I would have expected something like (M+Transpose[M])/2...Interestingly your result fullfills A==Floor[(M+Transpose[M])/2] !
      – Ulrich Neumann
      4 hours ago






    • 1




      @UlrichNeumann (M+Transpose[M])/2 is the symmetrized part, and in particular the orthogonal projection onto the linear space of symmetric matrices (orthogonal with respect to the Frobenius metric). But as by OP's examples, this was not what the OP asked for.
      – Henrik Schumacher
      4 hours ago










    • @Henrik: Referring to your last point, you are right that your code gives me what I wanted. I checked it with other examples and it works.
      – Tugrul Temel
      4 hours ago














    up vote
    2
    down vote



    accepted










    Maybe this is what you are looking for. I interpreted your question as if you want to replace all nonsymmetric entries of the input matrix by zeroes and as if the input matrix is not necessarily binary.



    A = M Subtract[1, Unitize[Subtract[Transpose[M], M]]];





    share|improve this answer






















    • Yes...That is what I wanted to have. Perfect...
      – Tugrul Temel
      4 hours ago






    • 1




      @HenrikSchumacher For the symmetric part of M I would have expected something like (M+Transpose[M])/2...Interestingly your result fullfills A==Floor[(M+Transpose[M])/2] !
      – Ulrich Neumann
      4 hours ago






    • 1




      @UlrichNeumann (M+Transpose[M])/2 is the symmetrized part, and in particular the orthogonal projection onto the linear space of symmetric matrices (orthogonal with respect to the Frobenius metric). But as by OP's examples, this was not what the OP asked for.
      – Henrik Schumacher
      4 hours ago










    • @Henrik: Referring to your last point, you are right that your code gives me what I wanted. I checked it with other examples and it works.
      – Tugrul Temel
      4 hours ago












    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    Maybe this is what you are looking for. I interpreted your question as if you want to replace all nonsymmetric entries of the input matrix by zeroes and as if the input matrix is not necessarily binary.



    A = M Subtract[1, Unitize[Subtract[Transpose[M], M]]];





    share|improve this answer














    Maybe this is what you are looking for. I interpreted your question as if you want to replace all nonsymmetric entries of the input matrix by zeroes and as if the input matrix is not necessarily binary.



    A = M Subtract[1, Unitize[Subtract[Transpose[M], M]]];






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 2 hours ago

























    answered 4 hours ago









    Henrik Schumacher

    43.2k262127




    43.2k262127











    • Yes...That is what I wanted to have. Perfect...
      – Tugrul Temel
      4 hours ago






    • 1




      @HenrikSchumacher For the symmetric part of M I would have expected something like (M+Transpose[M])/2...Interestingly your result fullfills A==Floor[(M+Transpose[M])/2] !
      – Ulrich Neumann
      4 hours ago






    • 1




      @UlrichNeumann (M+Transpose[M])/2 is the symmetrized part, and in particular the orthogonal projection onto the linear space of symmetric matrices (orthogonal with respect to the Frobenius metric). But as by OP's examples, this was not what the OP asked for.
      – Henrik Schumacher
      4 hours ago










    • @Henrik: Referring to your last point, you are right that your code gives me what I wanted. I checked it with other examples and it works.
      – Tugrul Temel
      4 hours ago
















    • Yes...That is what I wanted to have. Perfect...
      – Tugrul Temel
      4 hours ago






    • 1




      @HenrikSchumacher For the symmetric part of M I would have expected something like (M+Transpose[M])/2...Interestingly your result fullfills A==Floor[(M+Transpose[M])/2] !
      – Ulrich Neumann
      4 hours ago






    • 1




      @UlrichNeumann (M+Transpose[M])/2 is the symmetrized part, and in particular the orthogonal projection onto the linear space of symmetric matrices (orthogonal with respect to the Frobenius metric). But as by OP's examples, this was not what the OP asked for.
      – Henrik Schumacher
      4 hours ago










    • @Henrik: Referring to your last point, you are right that your code gives me what I wanted. I checked it with other examples and it works.
      – Tugrul Temel
      4 hours ago















    Yes...That is what I wanted to have. Perfect...
    – Tugrul Temel
    4 hours ago




    Yes...That is what I wanted to have. Perfect...
    – Tugrul Temel
    4 hours ago




    1




    1




    @HenrikSchumacher For the symmetric part of M I would have expected something like (M+Transpose[M])/2...Interestingly your result fullfills A==Floor[(M+Transpose[M])/2] !
    – Ulrich Neumann
    4 hours ago




    @HenrikSchumacher For the symmetric part of M I would have expected something like (M+Transpose[M])/2...Interestingly your result fullfills A==Floor[(M+Transpose[M])/2] !
    – Ulrich Neumann
    4 hours ago




    1




    1




    @UlrichNeumann (M+Transpose[M])/2 is the symmetrized part, and in particular the orthogonal projection onto the linear space of symmetric matrices (orthogonal with respect to the Frobenius metric). But as by OP's examples, this was not what the OP asked for.
    – Henrik Schumacher
    4 hours ago




    @UlrichNeumann (M+Transpose[M])/2 is the symmetrized part, and in particular the orthogonal projection onto the linear space of symmetric matrices (orthogonal with respect to the Frobenius metric). But as by OP's examples, this was not what the OP asked for.
    – Henrik Schumacher
    4 hours ago












    @Henrik: Referring to your last point, you are right that your code gives me what I wanted. I checked it with other examples and it works.
    – Tugrul Temel
    4 hours ago




    @Henrik: Referring to your last point, you are right that your code gives me what I wanted. I checked it with other examples and it works.
    – Tugrul Temel
    4 hours ago










    up vote
    5
    down vote













    Maybe a bit simpler:



    M Transpose[M]


    Comparing with Henrik's answer:



    M Subtract[1, Unitize[Subtract[Transpose[M], M]]] == M Transpose[M]
    True





    share|improve this answer




















    • Simpler indeed. But it will work only for binary matrices. Well, actually, it is still somewhat unclear, what the OP's usage spectrum and desired result in the general case is supposed to be. I interpreted it as if the OP wants to replace all nonsymmetric entries of the input matrix by zeroes.
      – Henrik Schumacher
      3 hours ago










    • @Henrik -- Agreed, I took the binary example suggested by the OP as indicating interest only in binary matrices.
      – bill s
      3 hours ago











    • @Henrik: I wanted to extract binary cells only: that is, if (i,j)==(j,i)==1, then keep them in the output matrix, otherwise place zeros to both cells. What you are saying in your comment is what I actually wanted: replace all non-symmetric entries of the input matrix with zeros. Is Bill's proposal equivalent to your proposal? I want to make sure this because in the original case with n=1000 I cannot check it visually.
      – Tugrul Temel
      2 hours ago






    • 1




      A simple example for which bill's and my proposals lead to different output is the matrix M = 1, 2,1,1. In general it is preferrable to post also all assumptions on the input data already in the question. Moreover your question leave a lot room for interpretation. Please specify exactly what the desired output for a general input matrix should be.
      – Henrik Schumacher
      2 hours ago











    • @Henrik: I will edit the question in line with your comment.
      – Tugrul Temel
      1 hour ago














    up vote
    5
    down vote













    Maybe a bit simpler:



    M Transpose[M]


    Comparing with Henrik's answer:



    M Subtract[1, Unitize[Subtract[Transpose[M], M]]] == M Transpose[M]
    True





    share|improve this answer




















    • Simpler indeed. But it will work only for binary matrices. Well, actually, it is still somewhat unclear, what the OP's usage spectrum and desired result in the general case is supposed to be. I interpreted it as if the OP wants to replace all nonsymmetric entries of the input matrix by zeroes.
      – Henrik Schumacher
      3 hours ago










    • @Henrik -- Agreed, I took the binary example suggested by the OP as indicating interest only in binary matrices.
      – bill s
      3 hours ago











    • @Henrik: I wanted to extract binary cells only: that is, if (i,j)==(j,i)==1, then keep them in the output matrix, otherwise place zeros to both cells. What you are saying in your comment is what I actually wanted: replace all non-symmetric entries of the input matrix with zeros. Is Bill's proposal equivalent to your proposal? I want to make sure this because in the original case with n=1000 I cannot check it visually.
      – Tugrul Temel
      2 hours ago






    • 1




      A simple example for which bill's and my proposals lead to different output is the matrix M = 1, 2,1,1. In general it is preferrable to post also all assumptions on the input data already in the question. Moreover your question leave a lot room for interpretation. Please specify exactly what the desired output for a general input matrix should be.
      – Henrik Schumacher
      2 hours ago











    • @Henrik: I will edit the question in line with your comment.
      – Tugrul Temel
      1 hour ago












    up vote
    5
    down vote










    up vote
    5
    down vote









    Maybe a bit simpler:



    M Transpose[M]


    Comparing with Henrik's answer:



    M Subtract[1, Unitize[Subtract[Transpose[M], M]]] == M Transpose[M]
    True





    share|improve this answer












    Maybe a bit simpler:



    M Transpose[M]


    Comparing with Henrik's answer:



    M Subtract[1, Unitize[Subtract[Transpose[M], M]]] == M Transpose[M]
    True






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 3 hours ago









    bill s

    51.9k375146




    51.9k375146











    • Simpler indeed. But it will work only for binary matrices. Well, actually, it is still somewhat unclear, what the OP's usage spectrum and desired result in the general case is supposed to be. I interpreted it as if the OP wants to replace all nonsymmetric entries of the input matrix by zeroes.
      – Henrik Schumacher
      3 hours ago










    • @Henrik -- Agreed, I took the binary example suggested by the OP as indicating interest only in binary matrices.
      – bill s
      3 hours ago











    • @Henrik: I wanted to extract binary cells only: that is, if (i,j)==(j,i)==1, then keep them in the output matrix, otherwise place zeros to both cells. What you are saying in your comment is what I actually wanted: replace all non-symmetric entries of the input matrix with zeros. Is Bill's proposal equivalent to your proposal? I want to make sure this because in the original case with n=1000 I cannot check it visually.
      – Tugrul Temel
      2 hours ago






    • 1




      A simple example for which bill's and my proposals lead to different output is the matrix M = 1, 2,1,1. In general it is preferrable to post also all assumptions on the input data already in the question. Moreover your question leave a lot room for interpretation. Please specify exactly what the desired output for a general input matrix should be.
      – Henrik Schumacher
      2 hours ago











    • @Henrik: I will edit the question in line with your comment.
      – Tugrul Temel
      1 hour ago
















    • Simpler indeed. But it will work only for binary matrices. Well, actually, it is still somewhat unclear, what the OP's usage spectrum and desired result in the general case is supposed to be. I interpreted it as if the OP wants to replace all nonsymmetric entries of the input matrix by zeroes.
      – Henrik Schumacher
      3 hours ago










    • @Henrik -- Agreed, I took the binary example suggested by the OP as indicating interest only in binary matrices.
      – bill s
      3 hours ago











    • @Henrik: I wanted to extract binary cells only: that is, if (i,j)==(j,i)==1, then keep them in the output matrix, otherwise place zeros to both cells. What you are saying in your comment is what I actually wanted: replace all non-symmetric entries of the input matrix with zeros. Is Bill's proposal equivalent to your proposal? I want to make sure this because in the original case with n=1000 I cannot check it visually.
      – Tugrul Temel
      2 hours ago






    • 1




      A simple example for which bill's and my proposals lead to different output is the matrix M = 1, 2,1,1. In general it is preferrable to post also all assumptions on the input data already in the question. Moreover your question leave a lot room for interpretation. Please specify exactly what the desired output for a general input matrix should be.
      – Henrik Schumacher
      2 hours ago











    • @Henrik: I will edit the question in line with your comment.
      – Tugrul Temel
      1 hour ago















    Simpler indeed. But it will work only for binary matrices. Well, actually, it is still somewhat unclear, what the OP's usage spectrum and desired result in the general case is supposed to be. I interpreted it as if the OP wants to replace all nonsymmetric entries of the input matrix by zeroes.
    – Henrik Schumacher
    3 hours ago




    Simpler indeed. But it will work only for binary matrices. Well, actually, it is still somewhat unclear, what the OP's usage spectrum and desired result in the general case is supposed to be. I interpreted it as if the OP wants to replace all nonsymmetric entries of the input matrix by zeroes.
    – Henrik Schumacher
    3 hours ago












    @Henrik -- Agreed, I took the binary example suggested by the OP as indicating interest only in binary matrices.
    – bill s
    3 hours ago





    @Henrik -- Agreed, I took the binary example suggested by the OP as indicating interest only in binary matrices.
    – bill s
    3 hours ago













    @Henrik: I wanted to extract binary cells only: that is, if (i,j)==(j,i)==1, then keep them in the output matrix, otherwise place zeros to both cells. What you are saying in your comment is what I actually wanted: replace all non-symmetric entries of the input matrix with zeros. Is Bill's proposal equivalent to your proposal? I want to make sure this because in the original case with n=1000 I cannot check it visually.
    – Tugrul Temel
    2 hours ago




    @Henrik: I wanted to extract binary cells only: that is, if (i,j)==(j,i)==1, then keep them in the output matrix, otherwise place zeros to both cells. What you are saying in your comment is what I actually wanted: replace all non-symmetric entries of the input matrix with zeros. Is Bill's proposal equivalent to your proposal? I want to make sure this because in the original case with n=1000 I cannot check it visually.
    – Tugrul Temel
    2 hours ago




    1




    1




    A simple example for which bill's and my proposals lead to different output is the matrix M = 1, 2,1,1. In general it is preferrable to post also all assumptions on the input data already in the question. Moreover your question leave a lot room for interpretation. Please specify exactly what the desired output for a general input matrix should be.
    – Henrik Schumacher
    2 hours ago





    A simple example for which bill's and my proposals lead to different output is the matrix M = 1, 2,1,1. In general it is preferrable to post also all assumptions on the input data already in the question. Moreover your question leave a lot room for interpretation. Please specify exactly what the desired output for a general input matrix should be.
    – Henrik Schumacher
    2 hours ago













    @Henrik: I will edit the question in line with your comment.
    – Tugrul Temel
    1 hour ago




    @Henrik: I will edit the question in line with your comment.
    – Tugrul Temel
    1 hour ago










    up vote
    1
    down vote













    A = Floor @ Symmetrize @ M;

    TeXForm @ MatrixForm @ A



    $left(
    beginarraycccccc
    0 & 1 & 1 & 0 & 1 & 0 \
    1 & 0 & 0 & 1 & 0 & 1 \
    1 & 0 & 0 & 0 & 0 & 0 \
    0 & 1 & 0 & 0 & 0 & 0 \
    1 & 0 & 0 & 0 & 0 & 0 \
    0 & 1 & 0 & 0 & 0 & 0 \
    endarray
    right)$




    Note: This is much slower than the methods in the answers by bill s and Henrik Schumacher.






    share|improve this answer


























      up vote
      1
      down vote













      A = Floor @ Symmetrize @ M;

      TeXForm @ MatrixForm @ A



      $left(
      beginarraycccccc
      0 & 1 & 1 & 0 & 1 & 0 \
      1 & 0 & 0 & 1 & 0 & 1 \
      1 & 0 & 0 & 0 & 0 & 0 \
      0 & 1 & 0 & 0 & 0 & 0 \
      1 & 0 & 0 & 0 & 0 & 0 \
      0 & 1 & 0 & 0 & 0 & 0 \
      endarray
      right)$




      Note: This is much slower than the methods in the answers by bill s and Henrik Schumacher.






      share|improve this answer
























        up vote
        1
        down vote










        up vote
        1
        down vote









        A = Floor @ Symmetrize @ M;

        TeXForm @ MatrixForm @ A



        $left(
        beginarraycccccc
        0 & 1 & 1 & 0 & 1 & 0 \
        1 & 0 & 0 & 1 & 0 & 1 \
        1 & 0 & 0 & 0 & 0 & 0 \
        0 & 1 & 0 & 0 & 0 & 0 \
        1 & 0 & 0 & 0 & 0 & 0 \
        0 & 1 & 0 & 0 & 0 & 0 \
        endarray
        right)$




        Note: This is much slower than the methods in the answers by bill s and Henrik Schumacher.






        share|improve this answer














        A = Floor @ Symmetrize @ M;

        TeXForm @ MatrixForm @ A



        $left(
        beginarraycccccc
        0 & 1 & 1 & 0 & 1 & 0 \
        1 & 0 & 0 & 1 & 0 & 1 \
        1 & 0 & 0 & 0 & 0 & 0 \
        0 & 1 & 0 & 0 & 0 & 0 \
        1 & 0 & 0 & 0 & 0 & 0 \
        0 & 1 & 0 & 0 & 0 & 0 \
        endarray
        right)$




        Note: This is much slower than the methods in the answers by bill s and Henrik Schumacher.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 4 mins ago

























        answered 1 hour ago









        kglr

        168k8191394




        168k8191394



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184809%2fextract-the-symmetric-matrix-built-in-another-matrix%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke