Extract the symmetric matrix built-in another matrix
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
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 1
s 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
add a comment |Â
up vote
5
down vote
favorite
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 1
s 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
Do you have a particular algorithm in mind?
â corey979
4 hours ago
@corey979: I do not have any algorithm in mind but maybeScan
can be used to collect the non-negative symmetric positions inM
.
â 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
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
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 1
s 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
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 1
s 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
matrix
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 maybeScan
can be used to collect the non-negative symmetric positions inM
.
â 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
add a comment |Â
Do you have a particular algorithm in mind?
â corey979
4 hours ago
@corey979: I do not have any algorithm in mind but maybeScan
can be used to collect the non-negative symmetric positions inM
.
â 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
add a comment |Â
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]]];
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 fullfillsA==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 yourcode
gives me what I wanted. I checked it with other examples and it works.
â Tugrul Temel
4 hours ago
add a comment |Â
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
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 placezeros
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 withn=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 matrixM = 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
add a comment |Â
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.
add a comment |Â
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]]];
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 fullfillsA==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 yourcode
gives me what I wanted. I checked it with other examples and it works.
â Tugrul Temel
4 hours ago
add a comment |Â
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]]];
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 fullfillsA==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 yourcode
gives me what I wanted. I checked it with other examples and it works.
â Tugrul Temel
4 hours ago
add a comment |Â
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]]];
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]]];
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 fullfillsA==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 yourcode
gives me what I wanted. I checked it with other examples and it works.
â Tugrul Temel
4 hours ago
add a comment |Â
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 fullfillsA==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 yourcode
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
add a comment |Â
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
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 placezeros
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 withn=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 matrixM = 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
add a comment |Â
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
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 placezeros
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 withn=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 matrixM = 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
add a comment |Â
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
Maybe a bit simpler:
M Transpose[M]
Comparing with Henrik's answer:
M Subtract[1, Unitize[Subtract[Transpose[M], M]]] == M Transpose[M]
True
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 placezeros
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 withn=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 matrixM = 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
add a comment |Â
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 placezeros
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 withn=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 matrixM = 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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited 4 mins ago
answered 1 hour ago
kglr
168k8191394
168k8191394
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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 inM
.â 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