July 8, 2016

Python3で「if a in b」をするときはsetを使うべし

タイトルの通りです。下のコードで確認しました。 データが増えてくると1万倍は変わるようです。 Python 3.5.1 |Anaconda 2.4.1 (64-bit)| (default, Dec 7 2015, 15:00:12) [MSC v.1900 64 bit (AMD64)] Type "copyright", "credits" or "license" for more information. IPython 4.0.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: %cpaste Pasting code; enter '--' alone on the line to stop or use Ctrl-D. Read more

July 7, 2016

numpy上で平均を求める v.s. Pandasで平均を求める

計算の待ち時間が長く感じることが増えたので調べる 結論は、numpyのみで計算した方が早い。 以下で確認した。 Python 3.5.1+ (default, Mar 30 2016, 22:46:26) Type "copyright", "credits" or "license" for more information. IPython 2.4.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: %cpaste Pasting code; enter '--' alone on the line to stop or use Ctrl-D. :import numpy as np :import time : :start = time. Read more

July 6, 2016

Pandasのappendが遅くて萎えた話

あまりにも処理に時間がかかるので、下のコードで確認した。 gepruo@ubuntu$ ipython3 Python 3.5.1+ (default, Mar 30 2016, 22:46:26) Type "copyright", "credits" or "license" for more information. IPython 2.4.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features.%quickref -> Quick reference.help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: %cpaste Pasting code; enter '--' alone on the line to stop or use Ctrl-D. :import pandas as pd :import time :start = time. Read more

© gepuro 2013