今回の内容

概念編 (先週の続き)

[edit]


多次元配列(ndarray: n-dimensional array)

[edit]

import numpy as np

x = np.array( [1,3])
y = np.array( [2,4])
print( np.dot(x,y) )

from numpy import array

x = array( [1,3])
y = array( [2,4])
print( np.dot(x,y) )

from numpy import array,dot

x = array( [1,3])
y = array( [2,4])
print( dot(x,y) )

from numpy import *

x = array( [1,3])
y = array( [2,4])
print( dot(x,y) )

多次元配列
arr = np.asarray([[1,2,3], [4,5,6]])

NumPyによるベクトル計算や行列計算

*  これまでやってきた,以下の,ベクトル計算,行列計算は,NumPyで実装されています.

内積,行列積

転置行列

距離


グラフを描きましょう

[edit]

import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()

matplotlib-fig_01.png


import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.ylabel('some numbers')
plt.show()

matplotlib-fig_02.png


import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()

matplotlib-fig_03.png


import matplotlib.pyplot as plt
import numpy as np

# evenly sampled time at 200ms intervals
t = np.arange(0., 5., 0.2)

# red dashes, blue squares and green triangles
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()

matplotlib-fig_04.png


import matplotlib.pyplot as plt
import numpy as np

data = {'a': np.arange(50),
        'c': np.random.randint(0, 50, 50),
        'd': np.random.randn(50)}
data['b'] = data['a'] + 10 * np.random.randn(50)
data['d'] = np.abs(data['d']) * 100

plt.scatter('a', 'b', c='c', s='d', data=data)
plt.xlabel('entry a')
plt.ylabel('entry b')
plt.show()


/!\ Edit conflict - other version:



/!\ Edit conflict - your version:



/!\ End of edit conflict


matplotlib-fig_05.png


import matplotlib.pyplot as plt
import numpy as np

def f(t):
    return np.exp(-t) * np.cos(2*np.pi*t)

t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)

plt.figure(1)
plt.subplot(211)
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')

plt.subplot(212)
plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
plt.show()

matplotlib-fig_06.png


import matplotlib.pyplot as plt
import numpy as np

mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)

# the histogram of the data
n, bins, patches = plt.hist(x, 50, density=1, facecolor='g', alpha=0.75)

plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()

matplotlib-fig_07.png


SoftEng: Pub/14/Summary (last edited 2019-01-16 17:39:25 by TadashiIijima)