numpy

<Python, numpy> 無限大

知ってましたか? pythonで無限大は、np.infか、float('inf')で表現するらしいっす。 In [1]: float('inf') Out[1]: inf In [2]: float('inf') == 0 Out[2]: False In [3]: float('inf') < 1 Out[3]: False In [4]: float('inf') > 1 Out[4]: True In [5]: i…

<Python, numpy> ランダム選択

numpyさんに、リストから適当に選択するメソッドがあったのでめも。 choiceちゅうらしい。 In [1]: import numpy as np In [2]: lst = ['hage', 'hagezo', 'hageshiku', 'hagetaka', 'hageo', 'hagekichi', 'hagesaburo'] In [3]: np.random.choice(lst) Out…

<Python, numpy> histogram

度数分布 /ヒストグラムhistogramのデータを作る。 グラフは、データフレームDataFrameがあれば、df.hist()で簡単につくれるが、、 numpy.histogramを使うらしい。 In [12]: df = pd.DataFrame([1,2,3,3,4,4,4,4,5,5,5,5,5,5,6,6,7,8,9,10]) In [13]: df Out…

<Python, seaborn, numpy> FacetGrid と distplot で2軸表記する。

seaborn.FacetGridとseaborn.distplot()で、縦軸y-axisを2軸にして、 かつ、 片方は度数 片方は正規分布曲線の確立密度 にする。 g.map()でちゃっと、できなかったので、 g.axesの1要素づつのインデックスをnp.nditer()でチクタク取り出して、 ax.twinx()で…

<Python, numpy> 空のアレイを作る(コピー元がある場合)

空emptyのアレイarrayの作り方(コピー元がある場合)。 np.empty_like()で作成。 In [14]: g.axes Out[14]: array([[<matplotlib.axes._subplots.AxesSubplot object at 0x2b035890a278>], [<matplotlib.axes._subplots.AxesSubplot object at 0x2b033df20a90>], [<matplotlib.axes._subplots.AxesSubplot object at 0x2b035b084fd0>], [</matplotlib.axes._subplots.axessubplot></matplotlib.axes._subplots.axessubplot></matplotlib.axes._subplots.axessubplot>

<Python, numpy> numpy.ndarrayの繰り返し

numpy.ndarrayの繰り返し方iterating。 次のアレイ インスタンスarray instanceがあった時、 In [110]: a Out[110]: array([[ 0, 2, 4], [ 6, 8, 10]]) In [111]: g.axes Out[111]: array([[<matplotlib.axes._subplots.AxesSubplot object at 0x2b3583026748>], [<matplotlib.axes._subplots.AxesSubplot object at 0x2b3582fbceb8>], [</matplotlib.axes._subplots.axessubplot></matplotlib.axes._subplots.axessubplot>

<Python, Json, numpy, pandas> json.dumps() ではまったこと。

json.dumps() ではまったこと。 numpy.int64は蹴られる。。。 In [1502]: a Out[1502]: [1, 2, 3] In [1503]: type(a[0]) Out[1503]: int In [1504]: b Out[1504]: [1.0, 2.0, 3.0] In [1505]: type(b[0]) Out[1505]: float In [1506]: s Out[1506]: 0 1 1 2…