ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 11 Oct 2011 08:16:49 -0500Counting number of trues in a 1000 line answerhttps://ask.sagemath.org/question/8368/counting-number-of-trues-in-a-1000-line-answer/
for y in range (1000):
F=matrix([[randint(0,1) for i in range(1,11)] for j in range(1,11)])
F.echelon_form()==identity_matrix(10)
I need help with this formula! We are supposed to find the number of outputted Trues in this statement. Either a percent answer or just the number true out of 1000 would be awesome!
I'm not very well versed in this programming language and any help with a description would be great!!
Tue, 11 Oct 2011 07:29:58 -0500https://ask.sagemath.org/question/8368/counting-number-of-trues-in-a-1000-line-answer/Answer by Brionur for <pre><code>for y in range (1000):
F=matrix([[randint(0,1) for i in range(1,11)] for j in range(1,11)])
F.echelon_form()==identity_matrix(10)
</code></pre>
<p>I need help with this formula! We are supposed to find the number of outputted Trues in this statement. Either a percent answer or just the number true out of 1000 would be awesome!</p>
<p>I'm not very well versed in this programming language and any help with a description would be great!!</p>
https://ask.sagemath.org/question/8368/counting-number-of-trues-in-a-1000-line-answer/?answer=12400#post-id-12400#3) Approximately 120/1000(Depending on the randomization)
var('x')
x=0
for y in range (1000):
F=matrix([[randint(0,1) for i in range(1,11)] for j in range(1,11)])
if (F.echelon_form()==identity_matrix(10)):
x=x+1
show(x/1000)Tue, 11 Oct 2011 07:50:02 -0500https://ask.sagemath.org/question/8368/counting-number-of-trues-in-a-1000-line-answer/?answer=12400#post-id-12400Comment by kcrisman for <h1>3) Approximately 120/1000(Depending on the randomization)</h1>
<pre><code>var('x')
x=0
for y in range (1000):
F=matrix([[randint(0,1) for i in range(1,11)] for j in range(1,11)])
if (F.echelon_form()==identity_matrix(10)):
x=x+1
show(x/1000)
</code></pre>
https://ask.sagemath.org/question/8368/counting-number-of-trues-in-a-1000-line-answer/?comment=21138#post-id-21138The "var('x')" in the first line is superfluous, since you rebind it to the integer 0 immediately after that. There are other ways you can do this, but this one has the advantage of being clear.Tue, 11 Oct 2011 08:12:51 -0500https://ask.sagemath.org/question/8368/counting-number-of-trues-in-a-1000-line-answer/?comment=21138#post-id-21138Answer by parzan for <pre><code>for y in range (1000):
F=matrix([[randint(0,1) for i in range(1,11)] for j in range(1,11)])
F.echelon_form()==identity_matrix(10)
</code></pre>
<p>I need help with this formula! We are supposed to find the number of outputted Trues in this statement. Either a percent answer or just the number true out of 1000 would be awesome!</p>
<p>I'm not very well versed in this programming language and any help with a description would be great!!</p>
https://ask.sagemath.org/question/8368/counting-number-of-trues-in-a-1000-line-answer/?answer=12457#post-id-12457In one line:
[random_matrix(ZZ,10,x=0,y=2).echelon_form()==identity_matrix(10) for i in range(1000)].count(true)Tue, 11 Oct 2011 08:13:19 -0500https://ask.sagemath.org/question/8368/counting-number-of-trues-in-a-1000-line-answer/?answer=12457#post-id-12457Comment by parzan for <p>In one line:</p>
<pre><code>[random_matrix(ZZ,10,x=0,y=2).echelon_form()==identity_matrix(10) for i in range(1000)].count(true)
</code></pre>
https://ask.sagemath.org/question/8368/counting-number-of-trues-in-a-1000-line-answer/?comment=21137#post-id-21137Following kcrisman, this has the disadvantage of being unclear, but you can learn a trick or two here :)Tue, 11 Oct 2011 08:16:49 -0500https://ask.sagemath.org/question/8368/counting-number-of-trues-in-a-1000-line-answer/?comment=21137#post-id-21137