In [1]:
import numpy as np
In [2]:
arr = np.arange(11)

arr
Out[2]:
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10])
In [3]:
# 平方根を計算する
np.sqrt(arr)
Out[3]:
array([ 0.        ,  1.        ,  1.41421356,  1.73205081,  2.        ,
        2.23606798,  2.44948974,  2.64575131,  2.82842712,  3.        ,
        3.16227766])
In [4]:
# 自然対数の底eの累乗
np.exp(arr)
Out[4]:
array([  1.00000000e+00,   2.71828183e+00,   7.38905610e+00,
         2.00855369e+01,   5.45981500e+01,   1.48413159e+02,
         4.03428793e+02,   1.09663316e+03,   2.98095799e+03,
         8.10308393e+03,   2.20264658e+04])
In [7]:
# 正規分布に従う乱数
A = np.random.randn(10)

A
Out[7]:
array([ -3.11107882e-01,  -2.39068257e-01,  -5.28049925e-01,
        -5.47855008e-01,  -1.22663428e+00,  -1.48924670e+00,
        -5.73344030e-01,  -8.21385630e-01,   7.93016177e-01,
         4.13389788e-04])
In [6]:
# 別のアレイも用意
B = np.random.randn(10)
B
Out[6]:
array([-0.67821545,  0.14765054, -1.63514336,  1.39597633, -0.31364609,
        1.42949959,  1.56775535, -0.37085336,  0.6136157 , -2.84923476])
In [8]:
# 2つのアレイを足す
np.add(A,B)
Out[8]:
array([-0.98932333, -0.09141771, -2.16319328,  0.84812133, -1.54028037,
       -0.0597471 ,  0.99441132, -1.19223899,  1.40663188, -2.84882137])
In [9]:
# 各要素の大きいほうを返す
np.maximum(A,B)
Out[9]:
array([ -3.11107882e-01,   1.47650544e-01,  -5.28049925e-01,
         1.39597633e+00,  -3.13646087e-01,   1.42949959e+00,
         1.56775535e+00,  -3.70853362e-01,   7.93016177e-01,
         4.13389788e-04])
In [10]:
# この他の演算子に関しては、numpyのドキュメントに詳しい情報があります。
website = "http://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs"
import webbrowser
webbrowser.open(website)
Out[10]:
True
In [ ]: