Mar-18-2019, 09:53 PM
unfortunately even with your new code, the outcome is still 1, no matter what.
Also, I am really not understanding these input choices:
symmetric_A = [[a, b, c],
[b, c, a],
[c, a, b]]
skew_A = [[0, -b, -c],
[b, 0, -a],
[c, a, 0]]
arbitrary_A = [[a, b, c],
[d, e, f],
[g, h, i]]
shouldn't the symmetric case be [[a,d,g],[b,e,h],[c,f,i]] ?
and the skew be [[-a,-d,-g],[-b,-e,-h],[-c,-f,-i]] ?
anyway,
I have rewritten my code this way but I still get 1.
Is that a way to slightly change the code underneath to make it work properly?
Why do I keep getting 1?
Also, I am really not understanding these input choices:
symmetric_A = [[a, b, c],
[b, c, a],
[c, a, b]]
skew_A = [[0, -b, -c],
[b, 0, -a],
[c, a, 0]]
arbitrary_A = [[a, b, c],
[d, e, f],
[g, h, i]]
shouldn't the symmetric case be [[a,d,g],[b,e,h],[c,f,i]] ?
and the skew be [[-a,-d,-g],[-b,-e,-h],[-c,-f,-i]] ?
anyway,
I have rewritten my code this way but I still get 1.
Is that a way to slightly change the code underneath to make it work properly?
Why do I keep getting 1?
import numpy as np from numpy import array a, b, c, d, e, f, g, h, i = 1,2,3,4,5,6,7,8,9 A=[[a, b, c], [d, e, f], [g, h, i]] def is_symmetric(A): return (np.array(A) == np.array(A.transpose())).all() def is_skew(A): return (np.array(A) == -np.array(A.transpose())).all() def test_matrix(A): if is_symmetric(np.all(A)): return 1 if is_skew(np.all(A)): return -1 else: return 0; print(test_matrix(A))