2011-12-10から1日間の記事一覧

lambda 演算と関数

lambda で演算する方 import numpy import time f = lambda x: x**2 def test0(n): """空""" t1=time.time() t2=time.time() print t2-t1 def test1(n): """内包表現""" t1=time.time() a=[ f(x) for x in range(n) ] t2=time.time() print t2-t1 def test2(…

ループまわすのと内包表現と numpy.array

ちょっとしたテスト import numpy import time def test0(n): """空""" t1=time.time() t2=time.time() print t2-t1 def test1(n): """内包表現""" t1=time.time() a=[ x for x in range(n) ] t2=time.time() print t2-t1 def test2(n): """append""" t1=tim…

tsv の読み込み

最近考えた TSV (tab separated values) 形式で書かれたデータファイルを読んで辞書のリストに登録する. import re tsvfile = "filename" f=open(tsv,"r") s=re.compile("[\t\s]") objects=map( lambda x: { "id" : int(x[0]), # ここら辺はそれぞれのデー…