>>> def test(func1, func2): ____a = [random.randrange(1,200) for _ in range(1000000)] ____b = [random.randrange(1,200) for _ in range(1000000)] ____timer(func1, a, b); timer(func2, a, b)
>>> test(oree, omae) oree time = 0.04913, return = 0.50930 omae time = 0.10629, return = 0.50930 >>> test(oree, omae) oree time = 0.05014, return = 0.49830 omae time = 0.09525, return = 0.49830 0681デフォルトの名無しさん2018/02/06(火) 17:27:43.34ID:b1TJyJgg sum(same) は len(same) より速いのか 0682デフォルトの名無しさん2018/02/06(火) 17:43:13.98ID:b1TJyJgg >>> def oree2(a,b): ____same = [1 for v1,v2 in zip_longest(a,b) if v1==v2] ____return len(same)/max(len(a), len(b)) * 100
>>> import time, random; import numpy as np; from itertools import zip_longest >>> def oree(a,b): same = [True for v1,v2 in zip_longest(a,b) if v1==v2] return len(same)/max(a.size, b.size) * 100
>>> def timer(func, *args): start = time.time() r = func(*args) end = time.time() print(f'{func.__name__} time = {end - start:.5f}, return = {r:.5f}')
>>> def test(func1, func2): a = np.array([random.randrange(1,200) for _ in range(1000000)]) b = np.array([random.randrange(1,200) for _ in range(1000000)]) timer(func1, a, b); timer(func2, a, b) a = np.array([_ for _ in range(1000000)]) b = np.array([_ for _ in range(1000000)]) timer(func1, a, b); timer(func2, a, b)
>>> test(oree, omae) 0705デフォルトの名無しさん2018/02/07(水) 10:17:04.97ID:mhmm9auu>>781 a = [random.randrange(1,10) for _ in range(1000000)] b = [random.randrange(1,10) for _ in range(1000000)] これするだけでも全然逆になるよね 0706デフォルトの名無しさん2018/02/07(水) 13:34:45.29ID:3kZshcC8https://ideone.com/9BD0zR
サンプルコードが出てくるし、pyqtを露わに使わなくて良いので、コードも書きやすいと思う 0708デフォルトの名無しさん2018/02/07(水) 16:07:52.51ID:bLqJ09hb a = [random.randrange(1,200) for _ in range(10000)] b = [random.randrange(1,200) for _ in range(10000)] print(np.linalg.matrix_rank(np.diag(a) - np.diag(b)) / a.size * 100) 0709デフォルトの名無しさん2018/02/08(木) 14:42:46.64ID:Ia7szBUl 皆さん、相談させてください。 魔方陣を5個吐き出すプログラムを作ったのですが、
import random
abc=[1,2,3,4,5,6,7,8,9] count=0 while count<5: ____random.shuffle(abc)
____if abc[0]+abc[1]+abc[2]==15 and abc[3]+abc[4]+abc[5]==15 and abc[6]+abc[7]+abc[8]==15\ and abc[0]+abc[3]+abc[6]==15 and abc[1]+abc[4]+abc[7]==15 and abc[2]+abc[5]+abc[8]==15\ and abc[0]+abc[4]+abc[8]==15 and abc[2]+abc[4]+abc[6]==15: ________print(abc[0],abc[1],abc[2]) ________print(abc[3],abc[4],abc[5]) ________print(abc[6],abc[7],abc[8]) ________count=count+1 ________print(count) ________print("------")
for i in range(9): ____place = choice(list_) ____list_.remove(place) ____print(list_) 0742遊園地2018/02/10(土) 10:07:15.25ID:PklGIWAk 全要素取るなら、len() の方が分かりやすい。