Python ( ) 2017. 11. 21. 1 1 2 Anaconda 2 3 Python 3 3.1 Python.......................... 3 3.2 IDLE Python....................... 5 4 NumPy 6 5 matplotlib 7 5.1.................................. 7 5.2.................................. 7 5.3...................... 9 6 Scipy 11 7 Sympy 12 7.1 Sympy.................................... 12 7.2 Sympy................................... 12 8 scikit-learn 14 A Anaconda 15 A.1 Python.................................. 15 A.2............................. 15 1 Anaconda( ) Python 1 Windows PC Mac OS Linux Anaconda 1 Python( ): http://www.python.jp/ 1
2 Anaconda Anaconda 2 ( ) (numpy, matplotlib, scipy, scikit-learn ) Anaconda python3 64bit PC 64bit 32bit 1. Anadonda https://www.continuum.io/downloads Windows Python 3 64bit NO THANKS 2. (400MB ) 3. ( ) Anaconda3-x.x.x-Windows_x86_64.exe ( x 4. Setup Next, I Agree( ), Next(Just Me ) 5. ( ) Destination Folder( ) C:\Anaconda3 ( or 2 ) C 6. Advanced Options 2 Install 7. Completed Next, Finish 8. Anaconda3 (64-bit) Anaconda IPython Jupyter Spyder 2 Anaconda python windows 2
3 Python Python OS 3.1 Python PC Windows python python Python C:\Anaconda3 python python python 1: Python Enter >>> print("hello") Hello Python 2: Enter 3
>>> exit() Enter 4
3.2 IDLE Python IDLE PC Windows idle idle Python C:\Anaconda3\Script python idle IDLE python 3: IDLE File New File Python sample 1.py print("hello") File Save Save as 4: Run Run Module IDLE Hello 5: 5
4 NumPy NumPy 3 IDLE Python (Sec. 3.2 ) π >>> import numpy >>> numpy.pi 6: 3 NumPy( ):http://www.numpy.org/ 6
5 matplotlib 5.1 matplotlib 4 IDLE Python (Sec. 3.2 ) File New File Python sample test.py import numpy as np import matplotlib.pyplot as plt x=np.arange(-3,3,0.1) y= np.sin(x) plt.plot(x,y) plt.show() Run Run Module 7: ( ) 5.2 Python sample 2.py from pylab import * subplot(111, axisbg= darkslategray ) #subplot(111, axisbg #ababab ) t = arange(0.0, 2.0, 0.01) s = sin(2*pi*t) plot(t, s, y ) xlabel( time (s), color= r ) ylabel( voltage (mv), color= 0.5 ) # grayscale color title( About as silly as it gets, folks, color= #afeeee ) show() 4 matplotlib( ) http://matplotlib.org/ 7
[1] sample_2.py sample 2.py Run Run Module 8: 5 5 http://matplotlib.org/gallery.html 8
5.3 ( ) 1 1.1 2 1.2 3 1.6 1 x 2 y [1] plot_graph_data.txt import matplotlib.pyplot as plt x=[] y=[] fp = open( plot_graph_data.txt, r ) for i, line in enumerate(fp): data=line.split() x.append(data[0]) y.append(data[1]) plt.plot(x,y, ro ) # red circle plt.title( My graph ) plt.xlabel( time (s) ) plt.ylabel( hight (m) ) plt.text(1.2, 1.2, Hello Hello, rotation=45) plt.xlim(0.0, 4.0) plt.ylim(0.0, 2.0) plt.show() [1] plot_graph.py 9: 9
plt.title( My graph ) 10
6 Scipy Scipy 6 IDLE Python (Sec. 3.2 ) π >>> import scipy >>> scipy.pi 10: 6 Scipy.org( ): http://www.scipy.org/ 11
7 Sympy 7.1 Sympy Sympy 7 IDLE Python (Sec. 3.2 ) π >>> from sympy import * >>> pi.evalf() 3.14159265358979 7.2 Sympy sympy Maxima Scipy Lecture Note Sec. 3.2 Sympy : Python 8 1( ) (1/2) + (1/3) = (5/6) >>> a = Rational(1,2) >>> b = Rational(1,3) >>> a+b 5/6 2( ) (x + y) 2 = x 2 + 2xy + y 2 >>> x = Symbol( x ) >>> y = Symbol( y ) >>> expand((x+y)**2) x**2 + 2*x*y + y**2 3( ) >>> x = Symbol( x ) >>> diff(x**2,x) 2*x 4( ) >>> x = Symbol( x ) >>> integrate(x**2, (x,0,1)) 1/3 5( ) x 2 1 = 0 7 Sympy( ): http://www.sympy.org/ 8 http://www.turbare.net/transl/scipy-lecture-notes/packages/sympy.html 12
>>> x = Symbol( x ) >>> solve(x**2-1) [-1, 1] 13
8 scikit-learn ( ) scikit-learn 9 IDLE Python (Sec. 3.2 ) >>> import sklearn scikit-learn [1] sample 4.py ( ) import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression # create samples sample_size = 30 err_sigma = 0.1 x = np.random.rand(sample_size, 1) err = err_sigma * np.random.randn(sample_size, 1) y = 3 * x + 1 + err # train a linear regression model regr = LinearRegression () regr.fit(x, y) # make predictions xt = np.linspace (0.0, 1.0, num = 1000).reshape((1000, 1)) yt = regr.predict (xt) # plot samples and regression result plt.plot(x, y, o ) plt.plot(xt, yt) plt.show() scikit-learn 11: 9 scikit learn( ): http://scikit-learn.org 14
A Anaconda Python Python2.7 Anaconda (Sec. 2) A.1 Python 1. Python https://www.python.org/downloads/windows/ Python 2.7 (2.7.x) Windows x86 MSI installer 2. ( ) python-2.7.x.msi ( x 3. (R) C:\Python2 C 4. Python (Sec. 3) A.2 NumPy, Scipy, matplotlib, scikit-learn 15
[1] http://www.damp.tottori-u.ac.jp/~hoshi/py.html 16