ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 25 Feb 2019 03:15:10 +0100Count number of ones in a set of matrixhttps://ask.sagemath.org/question/45540/count-number-of-ones-in-a-set-of-matrix/I am having the following code:
v = MatrixSpace(GF(2),2,2)
c = [0]*2
for vv in v.list():
t=sum(vv)
c = [x+y for x,y in zip(c,t)]
print c
My goal is to count how many '1s' that I have for each column within the set of matrices. For example with the first 4 matrices in the set:
[0 0] [1 0] [0 1] [0 0]
[0 0], [0 0], [0 0], [1 0]
I expect to receive [2,1] as a result, i.e. there are 2 of '1s' appear in the 1st column and 1 of '1s' appears in the 2nd column. However, I got [0, 1], because it's binary base.
Thank you for reading my problem and support :)imnvshMon, 25 Feb 2019 03:15:10 +0100https://ask.sagemath.org/question/45540/