Ask Your Question
1

Counting number of trues in a 1000 line answer

asked 2011-10-11 14:29:58 +0200

anonymous user

Anonymous

updated 2015-05-24 21:05:19 +0200

FrédéricC gravatar image
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!!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2011-10-11 14:50:02 +0200

Brionur gravatar image

updated 2011-10-11 15:09:00 +0200

parzan gravatar image

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)
edit flag offensive delete link more

Comments

1

The "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.

kcrisman gravatar imagekcrisman ( 2011-10-11 15:12:51 +0200 )edit
1

answered 2011-10-11 15:13:19 +0200

parzan gravatar image

In one line:

[random_matrix(ZZ,10,x=0,y=2).echelon_form()==identity_matrix(10) for i in range(1000)].count(true)
edit flag offensive delete link more

Comments

Following kcrisman, this has the disadvantage of being unclear, but you can learn a trick or two here :)

parzan gravatar imageparzan ( 2011-10-11 15:16:49 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-10-11 14:29:58 +0200

Seen: 438 times

Last updated: Oct 11 '11