numpy
numpy
2014-05-06
MacPorts + Python 2.7 で:
$ port select --list python Available versions for python: none python25-apple python26-apple python27 (active) python27-apple $ sudo port install python27 +universal +tkinter $ sudo port install py27-numpy py27-scipy py27-matplotlib $ python Python 2.7.6 (default, Nov 19 2013, 19:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> import scipy >>> import matplotlib
import してエラーがでないことを確認。
matplotlib?
しかし import matplotlib.pyplot あたりをやるとフリーズしてしまう。
matplotlib を使うのに sudo port install gnuplot は必要ないらしい。
mean/average
>>> import numpy as np >>> a = np.array([(1,2,3),(2,3,4),(3,4,5),(4,5,6)]) >>> a array([[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]) >>> np.average(a, axis=0) [ 2.5 3.5 4.5] >>> np.average(a, axis=1) [ 2. 3. 4. 5.] >>> a.mean(axis=0) array([ 2.5, 3.5, 4.5]) >>> a.mean(axis=1) array([ 2., 3., 4., 5.]) >>> a.mean(axis=-1) array([ 2., 3., 4., 5.])
リストに戻すには:
>>> m = a.mean(axis=0) >>> m array([ 2.5, 3.5, 4.5]) >>> type(m) <type 'numpy.ndarray'> >>> lst = m.tolist() >>> lst [2.5, 3.5, 4.5] >>> type(lst) <type 'list'>
numpy.txt · 最終更新: 2014/05/06 10:23 by Takuya Nishimoto