├── Makefile ├── README.md ├── advanced.aux ├── advanced.tex ├── ccicons.sty ├── contoh ├── .ipynb_checkpoints │ ├── Untitled1-checkpoint.ipynb │ ├── Untitled2-checkpoint.ipynb │ ├── jupyter-cobaplot-python3-checkpoint.ipynb │ ├── jupyter-json-checkpoint.ipynb │ └── jupyter-pandas-checkpoint.ipynb ├── buat-unicode.py ├── budi-unicode.txt ├── cli-args.py ├── cluster-create-pr.py ├── cluster-create.py ├── cluster-pr.csv ├── cluster.csv ├── cobahash.py ├── cobaplot-xy.py ├── cobaplot.py ├── data.txt ├── input.py ├── jupyter-cobaplot-python3.ipynb ├── jupyter-json.ipynb ├── jupyter-pandas.ipynb ├── kmeans.py ├── linear-regression-create.py ├── linear-regression-pr.csv ├── linear-regression.csv ├── linear-regression.py ├── list.py ├── log-processing │ └── parsing-access-log.py ├── loop.py ├── negatif.py ├── numpy-matrix.py ├── opencv-grey.py ├── pandas-readcsv.py ├── pandas-readplat.py ├── platnomor.csv ├── platnomor.xlsx ├── prosesteks.py ├── readcsv.py └── tf-grad-decent.py ├── graphics ├── 3cluster-kmeans.jpg ├── 3cluster.jpg ├── br-pixel-grey.png ├── br-pixel.png ├── cluster-create.jpg ├── google-colab.jpg ├── kecil.jpg ├── matplotlib-contoh1.png ├── matplotlib-contoh2.png ├── matplotlib-gausian.png └── random-data.png ├── opencv.tex ├── optparams.sty ├── pendahuluan.aux ├── pendahuluan.tex ├── pengantar.aux ├── pengantar.tex ├── python.aux ├── python.bbl ├── python.blg ├── python.idx ├── python.log ├── python.out ├── python.pdf ├── python.tex ├── python.toc ├── referensi.bib ├── tcpdump.aux ├── tricks.aux ├── tricks.tex ├── tufte-book.cls └── tufte-common.def /Makefile: -------------------------------------------------------------------------------- 1 | keamanan.pdf: *.tex 2 | pdflatex python.tex 3 | 4 | bib: 5 | bibtex python 6 | 7 | ALL: 8 | pdflatex python.tex 9 | pdflatex python.tex 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pemrograman Python 2 | 3 | *This is a Python programming book in Bahasa Indonesia.* 4 | 5 | Ini adalah draft buku pemrograman dengan menggunakan bahasa Python. 6 | Sebetulnya, lebih tepatnya, ini adalah catatan pemrograman saya yang terkait dengan bahasa Python. 7 | Buku ini didesain untuk digunakan mulai dari pemula sampai ke yang expert. 8 | 9 | Selamat menikmati. Semoga bermanfaat. 10 | 11 | Budi Rahardjo @rahard 12 | -------------------------------------------------------------------------------- /advanced.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\zref@newlabel[2]{} 4 | \@writefile{toc}{\contentsline {chapter}{\numberline {2}Koding Tingkat Medium}{25}{chapter.2}\protected@file@percent } 5 | \@writefile{lof}{\addvspace {10\p@ }} 6 | \@writefile{lot}{\addvspace {10\p@ }} 7 | \@writefile{toc}{\contentsline {section}{\numberline {2.1}Argumen CLI}{25}{section.2.1}\protected@file@percent } 8 | \@writefile{toc}{\contentsline {section}{\numberline {2.2}Numpy}{26}{section.2.2}\protected@file@percent } 9 | \@writefile{toc}{\contentsline {section}{\numberline {2.3}Matlplotlib}{28}{section.2.3}\protected@file@percent } 10 | \newpmemlabel{^_2}{29} 11 | \@writefile{lof}{\contentsline {figure}{\numberline {2.1}{\ignorespaces Contoh sederhana dari Matplotlib}}{29}{section.2.3}\protected@file@percent } 12 | \newlabel{fig:contoh1}{{2.1}{29}{Matlplotlib}{section.2.3}{}} 13 | \newpmemlabel{^_3}{29} 14 | \citation{tensorflowstarted} 15 | \@writefile{lof}{\contentsline {figure}{\numberline {2.2}{\ignorespaces Menampilkan Dua Dataset}}{30}{section.2.3}\protected@file@percent } 16 | \newlabel{fig:contoh2}{{2.2}{30}{Matlplotlib}{section.2.3}{}} 17 | \newpmemlabel{^_4}{30} 18 | \@writefile{lof}{\contentsline {figure}{\numberline {2.3}{\ignorespaces Contoh Random Data dan Tampilan Grafik}}{31}{section.2.3}\protected@file@percent } 19 | \newlabel{fig:random-gausian}{{2.3}{31}{Matlplotlib}{section.2.3}{}} 20 | \newpmemlabel{^_5}{32} 21 | \@writefile{lof}{\contentsline {figure}{\numberline {2.4}{\ignorespaces Contoh Pembangkitan Random Data}}{32}{section.2.3}\protected@file@percent } 22 | \newlabel{fig:randomnumpy}{{2.4}{32}{Matlplotlib}{section.2.3}{}} 23 | \newpmemlabel{^_6}{34} 24 | \@writefile{lof}{\contentsline {figure}{\numberline {2.5}{\ignorespaces Tiga cluster data}}{34}{section.2.3}\protected@file@percent } 25 | \newlabel{fig:clustercreate}{{2.5}{34}{Matlplotlib}{section.2.3}{}} 26 | \@writefile{toc}{\contentsline {section}{\numberline {2.4}Pandas}{35}{section.2.4}\protected@file@percent } 27 | \newpmemlabel{^_7}{36} 28 | \@writefile{lof}{\contentsline {figure}{\numberline {2.6}{\ignorespaces Tiga cluster data dengan Pandas}}{37}{section.2.4}\protected@file@percent } 29 | \newlabel{fig:3cluster}{{2.6}{37}{Pandas}{section.2.4}{}} 30 | \newpmemlabel{^_8}{37} 31 | \@writefile{toc}{\contentsline {section}{\numberline {2.5}OpenCV}{37}{section.2.5}\protected@file@percent } 32 | \@writefile{lof}{\contentsline {figure}{\numberline {2.7}{\ignorespaces Tiga cluster dengan k-means}}{38}{section.2.4}\protected@file@percent } 33 | \newlabel{fig:3cluster-kmeans}{{2.7}{38}{Pandas}{section.2.4}{}} 34 | \newpmemlabel{^_9}{38} 35 | \newpmemlabel{^_10}{38} 36 | \@writefile{toc}{\contentsline {section}{\numberline {2.6}Kriptografi}{38}{section.2.6}\protected@file@percent } 37 | \@writefile{lof}{\contentsline {figure}{\numberline {2.8}{\ignorespaces Gambar asli}}{39}{section.2.5}\protected@file@percent } 38 | \@writefile{lof}{\contentsline {figure}{\numberline {2.9}{\ignorespaces Hasil proses}}{39}{section.2.5}\protected@file@percent } 39 | \@writefile{toc}{\contentsline {subsection}{\numberline {2.6.1}Fungsi Hash}{40}{subsection.2.6.1}\protected@file@percent } 40 | \@setckpt{advanced}{ 41 | \setcounter{page}{41} 42 | \setcounter{equation}{0} 43 | \setcounter{enumi}{0} 44 | \setcounter{enumii}{0} 45 | \setcounter{enumiii}{0} 46 | \setcounter{enumiv}{0} 47 | \setcounter{footnote}{3} 48 | \setcounter{mpfootnote}{0} 49 | \setcounter{part}{0} 50 | \setcounter{chapter}{2} 51 | \setcounter{section}{6} 52 | \setcounter{subsection}{1} 53 | \setcounter{subsubsection}{0} 54 | \setcounter{paragraph}{0} 55 | \setcounter{subparagraph}{0} 56 | \setcounter{figure}{9} 57 | \setcounter{table}{0} 58 | \setcounter{Item}{0} 59 | \setcounter{bookmark@seq@number}{20} 60 | \setcounter{cp@cntr}{10} 61 | \setcounter{NAT@ctr}{0} 62 | \setcounter{@tufte@num@bibkeys}{0} 63 | \setcounter{Exercise}{0} 64 | \setcounter{Answer}{0} 65 | \setcounter{ExePart}{0} 66 | \setcounter{Question}{0} 67 | \setcounter{subQuestion}{0} 68 | \setcounter{subsubQuestion}{0} 69 | \setcounter{savedQuestion}{0} 70 | \setcounter{savedsubQuestion}{0} 71 | \setcounter{savedsubsubQuestion}{0} 72 | \setcounter{mdf@globalstyle@cnt}{0} 73 | \setcounter{mdfcountframes}{0} 74 | \setcounter{mdf@env@i}{0} 75 | \setcounter{mdf@env@ii}{0} 76 | \setcounter{mdf@zref@counter}{0} 77 | \setcounter{parentequation}{0} 78 | \setcounter{@pps}{0} 79 | \setcounter{@ppsavesec}{0} 80 | \setcounter{@ppsaveapp}{0} 81 | \setcounter{section@level}{0} 82 | } 83 | -------------------------------------------------------------------------------- /advanced.tex: -------------------------------------------------------------------------------- 1 | \chapter{Koding Tingkat Medium} 2 | Pada bagian ini akan dibahas berbagai pemrograman Python yang lebih {\em advanced}. 3 | Sebetulnya yang akan dibahas adalah contoh-contoh kode Python dengan menggunakan 4 | berbagai paket yang tersedia. 5 | 6 | \section{Argumen CLI} 7 | Seringkali kita harus membuat sebuah program dalam bentuk {\em command line interface} 8 | (CLI) yang kemudian membaca argumen yang diberikan. 9 | Misalnya kita ingin program kita memproses sebuah berkas yang namanya kita 10 | berikan di {\em command line}. 11 | 12 | \begin{verbatim} 13 | $ program filename.pdf 14 | \end{verbatim} 15 | 16 | Apa yang kita berikan kepada program di atas disebut {\em argument}. 17 | Pada contoh di atas, {\em argument}-nya adalah ``filename.pdf''. 18 | Program kita harus dapat membaca {\em argument} yang kita berikan kepada program 19 | tersebut. Bagaimana caranya? Ada banyak caranya. Salah satunya dicontohkan 20 | pada contoh berikut ini. 21 | 22 | \begin{verbatim} 23 | # contoh parsing argumen yang diberikan kepada program 24 | # beri nama skrip ini cli-args.py 25 | # cara menjalankan: 26 | # python3 cli-args.py opsi1 opsi2 opsi3 27 | # opsi bisa banyak 28 | 29 | import sys 30 | # periksa jumlah argumennya 31 | 32 | numberargs = len(sys.argv) 33 | # tanpa argumen, hasilnya akan 0 (nol) 34 | # nama skrip adalah sys.argv[0] 35 | 36 | # print argumen yang diberikan 37 | for i in range(numberargs): 38 | print(i, sys.argv[i]) 39 | \end{verbatim}} 40 | 41 | Dari contoh tersebut, Anda dapat mengembangkan hal-hal yang lain. 42 | Misalnya Anda ingin memastikan bahwa program Anda mendapatkan {\em argument} 43 | dalam jumlah yang cukup (misalnya harus 3). Jika argumen yang diberikan kurang, 44 | maka dia akan memberikan petunjuk cara penggunaan skrip (program) kita 45 | dan kemudian keluar (dengan exit). 46 | (Catatan: biasanya {\em exit} memiliki nilai tidak nol kalau ada kesalahan. 47 | Kalau keluar normal, angkanya nol.) 48 | 49 | \begin{verbatim} 50 | if (numberargs) < 4: 51 | print("Usage: " + sys.argv[0] + " data1 data2 data3") 52 | exit(1) 53 | 54 | \end{verbatim} 55 | 56 | \section{Numpy} 57 | {\em Numpy} adalah paket python untuk berbagai aplikasi {\em scientific}. 58 | Di dalamnya ada {\em N-dimensional object}, {\em linear algebra}, 59 | {\em Fourier transform}, dan seterusnya. 60 | Sebagai contoh, jika kita ingin membangkitkan bilangan random dengan 61 | distribusi tertentu (uniform atau normal), maka kita dapat menggunakan 62 | paket Numpy ini. 63 | Biasanya paket Numpy ini sudah terpasang ketika kita memasang Python, 64 | tetapi jika belum terpasang maka modul Numpy ini dapat kita pasang sendiri. 65 | 66 | \begin{verbatim} 67 | $ sudo pip install numpy 68 | \end{verbatim} 69 | 70 | Contoh-contoh penggunaan paket Numpy akan digabungkan dengan bagian lain. 71 | Berikut ini adalah contoh sederhana penggunaan dari Numpy. 72 | Contoh pertama adalah dalam hal matriks. 73 | 74 | \begin{verbatim} 75 | >>> import numpy as np 76 | >>> a = np.arange(15).reshape(3, 5) 77 | >>> a 78 | array([[ 0, 1, 2, 3, 4], 79 | [ 5, 6, 7, 8, 9], 80 | [10, 11, 12, 13, 14]]) 81 | \end{verbatim} 82 | 83 | Berikut adalah contoh operasional matriks dengan menggunakan numpy. 84 | Pertama, kita dapat membuat matriks $a$ dan $b$ kemudian menjumlahkan 85 | dan mengalikan matriks tersebut. 86 | 87 | \begin{equation*} 88 | A = 89 | \begin{bmatrix} 90 | 1 & 2 & 3 \\ 91 | 4 & 5 & 6 \\ 92 | 7 & 8 & 9 93 | \end{bmatrix} 94 | \quad 95 | B = 96 | \begin{bmatrix} 97 | 3 & 3 & 3 \\ 98 | 5 & 5 & 5 \\ 99 | 5 & 3 & 1 100 | \end{bmatrix} 101 | \quad 102 | C = A+B 103 | \quad 104 | D = A \times B 105 | \end{equation*} 106 | 107 | 108 | \begin{verbatim} 109 | import numpy as np 110 | a = np.array([[1,2,3],[4,5,6],[7,8,9]]) 111 | print(a) 112 | b = np.array([[3,3,3],[5,5,5],[5,3,1]]) 113 | print(b) 114 | c = a+b 115 | print(c) 116 | d = np.matmul(a, b) 117 | print(d) 118 | \end{verbatim} 119 | 120 | Keluaran dari perintah di atas adalah seperti ini. Pertama-tama ditampilkan 121 | matriks $a$ dan $b$, kemudian operasi penambahan dan perkalian. 122 | Perhatikan bahwa operasi perkalian matriks menggunakan fungsi {\em matmul}. 123 | \begin{verbatim} 124 | [1 2 3] 125 | [4 5 6] 126 | [7 8 9]] 127 | 128 | [[3 3 3] 129 | [5 5 5] 130 | [5 3 1]] 131 | 132 | [[ 4 5 6] 133 | [ 9 10 11] 134 | [12 11 10]] 135 | 136 | [[ 28 22 16] 137 | [ 67 55 43] 138 | [106 88 70]] 139 | \end{verbatim} 140 | 141 | Contoh-contoh di atas hanya sekedar ilustrasi bagaimana kita menggunakan 142 | modul {\em Numpy}. Secara umum, jika ada pemrosesan data yang multi dimensional 143 | dan seringkali terkait dengan operasi matematika, maka Numpy 144 | sangat bermanfaat. 145 | 146 | Mari kita gunakan Numpy lagi untuk beberapa contoh. 147 | Kali ini kita akan menggunakan Numpy untuk statistik. 148 | Berikut ini contoh untuk menghasilkan 20 bilangan bulat secara acak 149 | dengan rentang dari 50 sampai dengan 99 (misal ini adalah berat badan). 150 | 151 | \begin{verbatim} 152 | import numpy as np 153 | berat = np.random.randint(low=50, high=100, size=20) 154 | print(berat) 155 | 156 | [98 84 72 57 61 98 60 96 75 86 95 81 62 77 67 52 73 96 95 71] 157 | \end{verbatim} 158 | 159 | Data di atas dapat disimpan dalam berkas untuk digunakan dalam 160 | proses lain. Numpy memiliki fungsi untuk menyipan data tersebut. 161 | Sebagai contoh, jika kita ingin menyimpan data tersebut dalam 162 | berkas `berat.csv' maka dapat dilakukan seperti berikut. 163 | Perhatikan bahwa perinta `fmt' digunakan untuk memformat data 164 | sebagai bilangan bulat (integer). 165 | \begin{verbatim} 166 | np.savetxt("berat.csv", berat, fmt='%i') 167 | \end{verbatim} 168 | 169 | Data tersebut di kemudian hari dapat dibaca dengan menggunakan perintah 170 | seperti contoh berikut. (Sebagai catatan kita sudah tahu bahwa data di 171 | dalam berkas `berat.csv' tersebut tercatat masing-masing dalam satu baris. 172 | Jika satu baris memiliki lebih dari satu data yang dipisahkan oleh tanda koma, 173 | maka kita dapat menggunakan perintah tambahan delimiter=',') 174 | \begin{verbatim} 175 | from numpy import genfromtxt 176 | my_data = genfromtxt('berat.csv') 177 | print(my_data) 178 | \end{verbatim} 179 | 180 | 181 | \section{Matlplotlib} 182 | Salah satu aplikasi yang cukup sering dibutuhkan ketika kita membuat program 183 | untuk keperluan penelitian adalah membuat grafik (plot). 184 | Salah satu {\em library} yang baik untuk digunakan adalah {\em matplotlib}. 185 | Pada sistem Linux, paket ini membutuhkan paket lain, yaitu {\em python-tk}. 186 | Untuk itu python-tk ini harus dipasang dulu. 187 | Di bawah ini adalah contoh pemasangan python-tk di sistem Linux (berbasis Debian) 188 | dengan menggunakan perintah apt-get. 189 | 190 | \begin{verbatim} 191 | $ sudo apt-get install python-tk 192 | $ sudo pip install matplotlib 193 | \end{verbatim} 194 | 195 | Berikut ini adalah contoh sederhana penggunaan Numpy dan Matlplotlib. 196 | Pada contoh ini kita akan melakukan plot sebuah grafik sederhana 197 | dari sebuah dataset. 198 | Langkah pertama dalam menggunakan {\em matplotlib} adalah melakukan 199 | proses import seperti halnya di Numpy. 200 | Yang ingin kita gunakan adalah fungsi-fungsi dari pyplot. Ini kita 201 | persingkat dengan menggunakan {\em plt}. 202 | 203 | \begin{verbatim} 204 | import matplotlib.pyplot as plt 205 | 206 | x1 = [1, 2, 3, 4, 5] 207 | y1 = [2, 4, 6, 8, 10] 208 | plt.plot(x1, y1, c='blue', label='Dataset 1') 209 | plt.legend() 210 | plt.show() 211 | \end{verbatim} 212 | 213 | Contoh di atas akan menghasilkan sebuah grafik plot sebagaimana 214 | ditampilkan pada~\ref{fig:contoh1}. 215 | Kita dapat juga mengubah grafik menjadi {\em scatter plot} dengan 216 | mengubah perintah {\em plt.plot} menjadi {\em plt.scatter}. 217 | Silahkan dicoba. 218 | 219 | \begin{figure}[ht] 220 | \fbox{\includegraphics[width=1.0\linewidth]{graphics/matplotlib-contoh1.png}} 221 | \caption{Contoh sederhana dari Matplotlib} 222 | \label{fig:contoh1} 223 | \end{figure} 224 | 225 | Matplotlib dapat digunakan untuk menampilkan beberapa dataset sekaligus. 226 | Berikut ini contoh untuk menampilkan dua dataset sekaligus. 227 | Pada contoh ini kita menggunakan {\em scatter plot}. Tentu saja ini dapat 228 | juga digantikan dengan {\em line plot} sebagaimana ada dalam contoh sebelumnya. 229 | Hasilnya ditampilkan pada gambar~\ref{fig:contoh2}. 230 | 231 | \begin{verbatim} 232 | import matplotlib.pyplot as plt 233 | 234 | # dataset pertama 235 | x1 = [1, 2, 3, 4, 5] 236 | y1 = [2, 4, 6, 8, 10] 237 | # dataset kedua 238 | x2 = [1, 2, 3, 4, 5] 239 | y2 = [3, 1, 7, 5, 6] 240 | 241 | plt.scatter(x1, y1, c='blue', label='Dataset 1') 242 | plt.scatter(x2, y2, c='red', label='Dataset 2') 243 | plt.legend() 244 | plt.show() 245 | \end{verbatim} 246 | 247 | \begin{figure}[ht] 248 | \fbox{\includegraphics[width=1.0\linewidth]{graphics/matplotlib-contoh2.png}} 249 | \caption{Menampilkan Dua Dataset} 250 | \label{fig:contoh2} 251 | \end{figure} 252 | 253 | Pada contoh selanjutnya kita akan membuat data random sebanyak 200 buah 254 | dengan distribusi Normal dengan mean (loc) di 75. 255 | (Jika pilihan `loc' tidak disebutkan, maka mean yang akan digunakan adalah 0.0.) 256 | Data tersebut kita plot dengan pilihan {\em histogram}. 257 | Ada banyak pilihan, misalkan kita dapat plot dengan {\em bins} 258 | dalam rentang antara 50 dan 101. 259 | 260 | \begin{verbatim} 261 | import numpy as np 262 | import matplotlib.pyplot as plt 263 | 264 | berat = np.random.normal(loc=75, scale=10, size=200) 265 | 266 | # plt.hist(berat) 267 | plt.hist(berat, bins=range(50, 101), align='left') 268 | plt.xlabel('Berat') 269 | plt.ylabel('Jumlah orang') 270 | plt.show() 271 | \end{verbatim} 272 | 273 | \begin{figure}[ht] 274 | \fbox{\includegraphics[width=1.0\linewidth]{graphics/matplotlib-gausian.png}} 275 | \caption{Contoh Random Data dan Tampilan Grafik} 276 | \label{fig:random-gausian} 277 | \end{figure} 278 | 279 | Contoh dari tampilan kode di atas dapat dilihat pada 280 | Gambar~\ref{fig:random-gausian}. 281 | Gambar ini sangat sederhana dan dapat dimodifikasi tapilannya, 282 | warna, legend, label, dan seterusnya. 283 | Untuk melihat pilihan-pilihan apa saja yang tersedia dapat dilakukan 284 | dengan membaca dokumentasi dan melihat contoh-contoh. 285 | Misal, jika kita ingin mengganti warna dari bar chart tersebut 286 | menjadi warna merah, tambahkan "Color='Red'" pada baris yang 287 | dimulai dengan {\tt plt.hist}. 288 | 289 | 290 | Berikut ini adalah sebuah contoh penggunaan Matplotlib dan Numpy. Pada contoh ini kita akan membuat kumpulan data yang memiliki karakteristik ``sekitar'' persamaan 291 | $Y = Ax + b$. 292 | Untuk itu perlu dihasilkan data yang sudah ditambahi atau dikurangi dengan angka random (yang dibuat dengan menggunakan Numpy). (Kode ini diambil dari buku ``Getting Started with Tensorflow''\cite{tensorflowstarted}.) 293 | Hasilnya dapat dilihat pada gambar~\ref{fig:randomnumpy} 294 | 295 | 296 | \begin{verbatim} 297 | import numpy as np 298 | import matplotlib.pyplot as plt 299 | 300 | # persamaan y = a*x + b 301 | a = 0.25 302 | b = 0.75 303 | jumlah_titik = 300 304 | 305 | # buat dua list yang masih kosong 306 | x_point = [] 307 | y_point = [] 308 | 309 | for i in range(jumlah_titik): 310 | x = np.random.normal(0.0,0.4) 311 | y = a*x + b + np.random.normal(0.0,0.1) 312 | x_point.append([x]) 313 | y_point.append([y]) 314 | 315 | plt.plot(x_point,y_point,'o',label='Random Data') 316 | plt.legend() 317 | plt.show() 318 | \end{verbatim} 319 | 320 | 321 | \begin{figure}[ht] 322 | \fbox{\includegraphics[width=1.0\linewidth]{graphics/random-data.png}} 323 | \caption{Contoh Pembangkitan Random Data} 324 | \label{fig:randomnumpy} 325 | \end{figure} 326 | 327 | Jika kode di atas ingin dijalankan di dalam {\em Jupyter Notebook}, 328 | maka baris pertama perlu ditambahkan ini: 329 | 330 | \begin{verbatim} 331 | %matplotlib notebook 332 | \end{verbatim} 333 | 334 | Data ($x$ dan $y$) pada contoh di atas dapat disimpan (diekspor) ke berkas 335 | dalam format CSV ({\em comma separated value}) dengan menggunakan Numpy 336 | seperti contoh di bawah ini. 337 | Berkas ``linear-regression.csv'' disimpan pada direktori dimana kode 338 | ini dijalankan. Variabel $x\_point$ dan $y\_point$ akan dimasukkan ke 339 | berkas tersebut dengan format yang didefinisikan dalam {\em fmt}. 340 | Pada contoh di bawah ini format yang akan digunakan adalah 341 | {\em floating point} dengan 5 digit di belakang koma. 342 | Variabel tersebut dipisahkan dengan menggunakan koma (,) sebagaimana 343 | dijabarkan dalam {\em delimiter}. 344 | 345 | \begin{verbatim} 346 | np.savetxt("linear-regression.csv", np.column_stack([x_point, y_point]), fmt='%.5f', delimiter=', ') 347 | \end{verbatim} 348 | 349 | Data di atas dapat dibaca kembali dari berkas CSV dan dilakukan 350 | perhitungan ({\em linear regression}) untuk mencari faktor {\em gradient} 351 | (faktor $A$) dan $b$ dalam persamaan $Y = a*x + b$. 352 | Perhitungan ini membutuhkan modul {\em Scipy} yang harus dipasang 353 | secara terpisah. (Gunakan pip untuk memasang modul scipy itu.) 354 | 355 | \begin{verbatim} 356 | #read CSV of data and calculate a and b 357 | # y = ax + b 358 | import numpy as np 359 | # do not forget to install scipy first: python3 -m pip install scipy 360 | from scipy import stats 361 | 362 | my_csv = np.genfromtxt('linear-regression.csv', delimiter=',') 363 | xp, yp = my_csv.transpose() 364 | gradient,intercept,r_value,p_value,std_err=stats.linregress(xp,yp) 365 | print("Gradient and intercept",gradient,intercept) 366 | print("R-squared",r_value**2) 367 | print("p-value",p_value) 368 | \end{verbatim} 369 | 370 | Jika diperlukan, data tersebut dapat ditampilkan ulang dan garis (lurus) 371 | dapat digambarkan pula. 372 | 373 | 374 | Berikut ini adalah contoh lain untuk membuat dataset, menggunakan fungsi, 375 | dan juga menampilkannya dalam grafik (scattered plot). 376 | Dalam contoh ini kita akan membuat sebuah dataset yang terdiri dari 3~kelas. 377 | Masing-masing kelas memiliki titik pusat (centroid) yang berbeda. 378 | Semua data dimasukkan ke dalam satu {\em list} yang sama. 379 | Pura-puranya kita tidak tahu bahwa kita memiliki tiga kelas. 380 | (Nanti ini akan kita proses secara statistik untuk menentukan kelas tersebut.) 381 | 382 | \begin{verbatim} 383 | import numpy as np 384 | import matplotlib.pyplot as plt 385 | 386 | # buat function dulu 387 | def buat_list(cx,cy): 388 | x_point.append([cx]) 389 | y_point.append([cy]) 390 | for i in range(jumlah_data): 391 | x = cx + np.random.normal(0.0,0.7) 392 | y = cy + np.random.normal(0.0,0.7) 393 | x_point.append([x]) 394 | y_point.append([y]) 395 | 396 | jumlah_data=100 397 | x_point = [] 398 | y_point = [] 399 | # cluster pertama, centroid di (10, 4,5) 400 | buat_list(10.0, 4.5) 401 | # cluster kedua, centroid di (3.5, 2.5) 402 | buat_list(3.5, 2.5) 403 | # cluster ketiga, centroid di (4.5, 8.5) 404 | buat_list(4.5, 8.5) 405 | # simpan dalam bentuk CSV 406 | np.savetxt("cluster.csv", np.column_stack([x_point, y_point]), fmt='%.5f', delimiter=', ') 407 | 408 | plt.plot(x_point,y_point, 'x') 409 | plt.show() 410 | \end{verbatim} 411 | 412 | Jika kode di atas kita jalankan, maka hasilnya adalah sebuah tampilan 413 | seperti yang ditunjukkan pada gambar~\ref{fig:clustercreate}. 414 | Pada gambar ini, semua data ditampilkan seperti satu kelas saja dan 415 | semua ditampilkan menggunakan simbol $x$. Padahal dengan mudahnya kita 416 | dapat melihat bahwa data tersebut terdiri dari tiga kelas. 417 | 418 | \begin{figure}[ht] 419 | \fbox{\includegraphics[width=1.0\linewidth]{graphics/cluster-create.jpg}} 420 | \caption{Tiga cluster data} 421 | \label{fig:clustercreate} 422 | \end{figure} 423 | 424 | Kode di atas juga menunjukkan cara menggunakan fungsi di Python dan bagaimana 425 | memberikan parameter kepada fungsi tersebut. 426 | Ini adalah contoh, {\em pass by value}, yang mana nilai dari centroid 427 | diberikan ke fungsi dan akan mengisi variabel $cx$ dan $cy$ di dalam fungsi 428 | tersebut. 429 | Nanti akan dibahas juga bagaimana melakukan {\em pass by reference}. 430 | Juga dalam contoh ini, beberapa variabel masih menggunakan variabel global, 431 | yang mana ini adalah contoh yang kurang baik. 432 | 433 | \section{Pandas} 434 | Pandas adalah library untuk data processing. Dia banyak digunakan untuk 435 | berbagai aplikasi, seperti misalnya di {\em Artificial Intelligence} 436 | (AI) atau {\em Machine Learning}, statistik, dan operasi yang melibatkan 437 | banyak data dalam bentuk tabel. 438 | Bayangkan ini seperti menggunakan {\em spreadsheet} (seperti Excel). 439 | 440 | Langkah pertama yang dilakukan adalah memasang Pandas. 441 | Jika Anda menggunakan Python3, maka gunakan perintah berikut. 442 | \begin{verbatim} 443 | $ sudo python3 -m pip install pandas 444 | \end{verbatim} 445 | 446 | Setelah Pandas terpasang, mari kita coba membuat sebuat {\em Series}. 447 | Kali ini dia berisi data bilangan dan $NaN$. 448 | Pandas akan secara otomatis membuat indeks dari data tersebut (dengan 449 | index bilangan integer)\footnote{Contoh lain dapat dilihat di 450 | https://pandas.pydata.org/pandas-docs/stable/10min.html}. 451 | 452 | \begin{verbatim} 453 | import pandas as pd 454 | import numpy as np 455 | import matplotlib.pyplot as plt 456 | 457 | # create series 458 | ser = pd.Series([1,3,5,7,np.nan,9,11]) 459 | print(ser) 460 | \end{verbatim} 461 | 462 | Hasilnya adalah sebagai berikut. Perhatikan bentuk keluarannya 463 | yang seperti tabel dalam {\em spreadsheet}. 464 | \begin{verbatim} 465 | 0 1.0 466 | 1 3.0 467 | 2 5.0 468 | 3 7.0 469 | 4 NaN 470 | 5 9.0 471 | 6 11.0 472 | dtype: float64 473 | \end{verbatim} 474 | 475 | Pandas dapat membaca data dalam bentuk CSV. 476 | Berikut ini adalah contoh kode yang membaca data dari berkas 'cluster.csv' 477 | (yang sebelumnya pernah kita buat). 478 | 479 | \begin{verbatim} 480 | import pandas as pd 481 | df = pd.read_csv('cluster.csv', header=None) 482 | # tambahkan label di kolomnya (tidak harus) 483 | df.columns = ['x', 'y'] 484 | print(df) 485 | \end{verbatim} 486 | 487 | 488 | Mari kita lanjutkan contoh penggunaan Pandas untuk melakukan analisis 489 | statistik, yaitu {\em clustering} dengan menggunakan {\em k-means}. 490 | (Mengenai statistik ini ada dibahas di buku lain. 491 | Akan saya berikan referensinya di versi berikutnya.) 492 | Pada contoh sebelumnya kita membaca berkas cluster.csv yang di dalamnya 493 | berisi data yang terkumpul dalam tiga {\em cluster}. 494 | Kita ulangi lagi kodenya, akan tetapi sekarang kita tambahkan visualisasi 495 | (scattered graph) yang dapat dilakukan dengan menggunakan Pandasa. 496 | (Catatan: pada bagian akhir dibutuhkan perintah plt.show() agar grafik 497 | dapat ditampilkan.) 498 | 499 | \begin{verbatim} 500 | import pandas as pd 501 | import matplotlib.pyplot as plt 502 | 503 | # baca data dahulu 504 | df = pd.read_csv('cluster.csv', header=None) 505 | df.columns = ['x', 'y'] 506 | df.plot.scatter(x = 'x', y='y', c='red') 507 | plt.show() 508 | \end{verbatim} 509 | 510 | Hasil dari kode di atas adalah tampilan grafik yang mirip dengan 511 | yang sudah kita lakukan dengan menggunakan Matplotlib. 512 | (Lihat gambar~\ref{fig:3cluster}.) 513 | 514 | \begin{figure}[ht] 515 | \fbox{\includegraphics[width=1.0\linewidth]{graphics/3cluster.jpg}} 516 | \caption{Tiga cluster data dengan Pandas} 517 | \label{fig:3cluster} 518 | \end{figure} 519 | 520 | Mari kita lanjutkan dengan melakukan {\em clustering}. 521 | Hal ini dapat kita lakukan dengan menggunakan pustaka ({\em library}) 522 | lain, yaitu {\em Sklearn}. 523 | Tambahkan kode berikut ini ke kode sebelumnya. 524 | 525 | \begin{verbatim} 526 | from sklearn.cluster import KMeans 527 | kmeans = KMeans(n_clusters=3).fit(df) 528 | centroids = kmeans.cluster_centers_ 529 | print(centroids) 530 | # tampilkan secara visual 531 | plt.scatter(df['x'],df['y'], c=kmeans.labels_.astype(float),s=50,alpha=0.5) 532 | plt.scatter(centroids[:, 0], centroids[:, 1], c='red') 533 | plt.show() 534 | \end{verbatim} 535 | 536 | Hasil dari kode di atas adalah tampilan tiga {\em cluster} 537 | beserta {\em centroidnya}. 538 | (Lihat gambar~\ref{fig:3cluster-kmeans}.) 539 | Anda dapat mengubah-ubah jumlah {\em cluster}-nya dengan mengubah 540 | variabel $n\_clusters$. Misal, Anda dapat menggantikan angka 3 menjadi 4 541 | untuk membuatnya menjadi 4 {\em cluster}. 542 | Pemilihan jumlah kluster yang paling optimal dapat dilakukan, tetapi 543 | ini akan menjadi pembahasan yang terpisah. 544 | Perlu diingat juga bahwa algoritma {\em k-means} yang kita gunakan ini 545 | akan menghasilkan urutan penomoran kluster yang berbeda 546 | setiap kita menjalankan kode ini. 547 | 548 | \begin{figure}[ht] 549 | \fbox{\includegraphics[width=1.0\linewidth]{graphics/3cluster-kmeans.jpg}} 550 | \caption{Tiga cluster dengan k-means} 551 | \label{fig:3cluster-kmeans} 552 | \end{figure} 553 | 554 | Demikianlah sedikit contoh-contoh dari penggunaan pustaka Pandas. 555 | Pada prinsipnya jika ada masalah yang dalam pemikiran kita bentuknya 556 | adalah tabel (seperti {\em spreadsheet}), maka solusi dapat dilakukan 557 | dengan menggunakan Pandas. 558 | 559 | 560 | 561 | 562 | \input{opencv} 563 | 564 | \section{Kriptografi} 565 | Sebagaimana bidang lain, Python memiliki {\em library} yang lengkap untuk 566 | kriptografi. Berikut ini hanya beberapa contoh penggunaan {\em library} 567 | tersebut. 568 | 569 | \subsection{Fungsi Hash} 570 | Fungsi hash adalah fungsi satu arah yang memberikan tanda ({\em signature}) 571 | dari data digital; {\em stream of data} dan berkas. 572 | Perubahan satu bit saja dari data tersebut akan mengubah nilai dari 573 | {\em hash} yang dihasilkan. Itulah sebabnya fungsi {\em hash} dapat 574 | digunakan untuk menjamin integritas data. 575 | 576 | Ada banyak algoritma fungsi hash. Algoritma yang terkenal adalah MD5 577 | dan SHA. Saat ini MD5 sudah dianggap tidak layak lagi karena sudah 578 | ditemukan {\em collision}, yaitu nilai {\em hash} yang sama untuk data 579 | yang berbeda. SHA~256 merupakan algoritma yang dianggap cocok saat ini. 580 | 581 | \begin{verbatim} 582 | unix$ echo "beli 10000" | shasum -a 256 583 | 375a6c46228994656932f4aa17d9ae50f21da75a31ff17f8517c255c06cba809 - 584 | 585 | unix$ cat pesan1.txt 586 | beli 10000 587 | unix$ shasum -a 256 pesan1.txt 588 | 375a6c46228994656932f4aa17d9ae50f21da75a31ff17f8517c255c06cba809 pesan1.txt 589 | 590 | unix$ cat pesan2.txt 591 | beli 1000 592 | unix$ shasum -a 256 pesan2.txt 593 | 5901bccc6a0556fac2b4a164ef831a7ed4ceddeb60c6ddde1162f5a40b9d2917 pesan2.txt 594 | \end{verbatim} 595 | 596 | Contoh kode Python untuk hal di atas adalah sebagai berikut: 597 | 598 | \begin{verbatim} 599 | # Contoh fungsi hash 600 | import hashlib 601 | h = hashlib.sha256("beli 10000\n") 602 | print h.hexdigest() 603 | \end{verbatim} 604 | 605 | 606 | Salah satu pemanfaatan ``baru'' dari fungsi {\em hash} ini adalah pada 607 | algoritma {\em Blockchain} yang digunakan pada {\em Bitcoin}. Sedikit 608 | cerita tentang hal ini ada di blog 609 | saya~\footnote{https://rahard.wordpress.com/2018/03/10/berburu-hash/}. 610 | -------------------------------------------------------------------------------- /ccicons.sty: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `ccicons.sty', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% ccicons.dtx (with options: `package') 8 | %% 9 | %% This is a generated file. 10 | %% 11 | %% Copyright (C) 2011-2017 by Michael Ummels 12 | %% 13 | %% This work may be distributed and/or modified under the 14 | %% conditions of the LaTeX Project Public License, either version 1.3c 15 | %% of this license or (at your option) any later version. 16 | %% The latest version of this license is in 17 | %% http://www.latex-project.org/lppl.txt 18 | %% and version 1.3 or later is part of all distributions of LaTeX 19 | %% version 2005/12/01 or later. 20 | %% 21 | %% This work has the LPPL maintenance status `maintained'. 22 | %% 23 | %% The Current Maintainer of this work is Michael Ummels. 24 | %% 25 | %% This work consists of the files ccicons.dtx, ccicons.ins 26 | %% and the derived files ccicons.pdf and ccicons.sty. 27 | %% 28 | \NeedsTeXFormat{LaTeX2e}[1999/12/01] 29 | \ProvidesPackage{ccicons}[2017/10/30 v1.6 LaTeX support for Creative Commons icons] 30 | \RequirePackage{xkeyval} 31 | \define@boolkey{ccicons.sty}[ccicons@]{copyright}[true]{} 32 | \newcommand{\ccicons@scale}{1.0} 33 | \define@key{ccicons.sty}{scale}{\renewcommand\ccicons@scale{#1}} 34 | \ProcessOptionsX 35 | \DeclareFontFamily{U}{ccicons}{} 36 | \DeclareFontShape{U}{ccicons}{m}{n}{ 37 | <-> s * [\ccicons@scale] ccicons 38 | }{} 39 | \newcommand{\ccicons@font}{\usefont{U}{ccicons}{m}{n}} 40 | \newcommand{\ccicons@logo}{\char0} 41 | \newcommand{\ccicons@by}{\char1} 42 | \newcommand{\ccicons@sa}{\char2} 43 | \newcommand{\ccicons@nd}{\char3} 44 | \newcommand{\ccicons@nc}{\char4} 45 | \newcommand{\ccicons@nceu}{\char5} 46 | \newcommand{\ccicons@ncjp}{\char6} 47 | \newcommand{\ccicons@pd}{\char7} 48 | \newcommand{\ccicons@zero}{\char8} 49 | \newcommand{\ccicons@sampling}{\char9} 50 | \newcommand{\ccicons@share}{\char10} 51 | \newcommand{\ccicons@remix}{\char11} 52 | \newcommand{\ccicons@copy}{\char12} 53 | \newcommand{\ccicons@pdalt}{\char13} 54 | \newcommand{\ccLogo}{{\ccicons@font\ccicons@logo}} 55 | \newcommand{\ccAttribution}{{\ccicons@font\ccicons@by}} 56 | \newcommand{\ccShareAlike}{{\ccicons@font\ccicons@sa}} 57 | \newcommand{\ccNoDerivatives}{{\ccicons@font\ccicons@nd}} 58 | \newcommand{\ccNonCommercial}{{\ccicons@font\ccicons@nc}} 59 | \newcommand{\ccNonCommercialEU}{{\ccicons@font\ccicons@nceu}} 60 | \newcommand{\ccNonCommercialJP}{{\ccicons@font\ccicons@ncjp}} 61 | \newcommand{\ccPublicDomain}{{\ccicons@font\ccicons@pd}} 62 | \newcommand{\ccPublicDomainAlt}{{\ccicons@font\ccicons@pdalt}} 63 | \newcommand{\ccZero}{{\ccicons@font\ccicons@zero}} 64 | \newcommand{\ccSampling}{{\ccicons@font\ccicons@sampling}} 65 | \newcommand{\ccShare}{{\ccicons@font\ccicons@share}} 66 | \newcommand{\ccRemix}{{\ccicons@font\ccicons@remix}} 67 | \newcommand{\ccCopy}{{\ccicons@font\ccicons@copy}} 68 | \ifccicons@copyright\renewcommand{\textcopyright}{\ccCopy}\fi 69 | \newcommand{\ccby}% 70 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by}} 71 | \newcommand{\ccbysa}% 72 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by% 73 | \kern0.1em\ccicons@sa}} 74 | \newcommand{\ccbynd}% 75 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by% 76 | \kern0.1em\ccicons@nd}} 77 | \newcommand{\ccbync}% 78 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by% 79 | \kern0.1em\ccicons@nc}} 80 | \newcommand{\ccbynceu}% 81 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by% 82 | \kern0.1em\ccicons@nceu}} 83 | \newcommand{\ccbyncjp}% 84 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by% 85 | \kern0.1em\ccicons@ncjp}} 86 | \newcommand{\ccbyncsa}% 87 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by% 88 | \kern0.1em\ccicons@nc\kern0.1em\ccicons@sa}} 89 | \newcommand{\ccbyncsaeu}% 90 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by% 91 | \kern0.1em\ccicons@nceu\kern0.1em\ccicons@sa}} 92 | \newcommand{\ccbyncsajp}% 93 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by% 94 | \kern0.1em\ccicons@ncjp\kern0.1em\ccicons@sa}} 95 | \newcommand{\ccbyncnd}% 96 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by% 97 | \kern0.1em\ccicons@nc\kern0.1em\ccicons@nd}} 98 | \newcommand{\ccbyncndeu}% 99 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by% 100 | \kern0.1em\ccicons@nceu\kern0.1em\ccicons@nd}} 101 | \newcommand{\ccbyncndjp}% 102 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@by% 103 | \kern0.1em\ccicons@ncjp\kern0.1em\ccicons@nd}} 104 | \newcommand{\cczero}% 105 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@zero}} 106 | \newcommand{\ccpd}% 107 | {\mbox{\ccicons@font\ccicons@logo\kern0.1em\ccicons@pd}} 108 | %% 109 | %% 110 | %% End of file `ccicons.sty'. 111 | -------------------------------------------------------------------------------- /contoh/.ipynb_checkpoints/Untitled1-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 2 6 | } 7 | -------------------------------------------------------------------------------- /contoh/.ipynb_checkpoints/Untitled2-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 2 6 | } 7 | -------------------------------------------------------------------------------- /contoh/.ipynb_checkpoints/jupyter-json-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 2 6 | } 7 | -------------------------------------------------------------------------------- /contoh/.ipynb_checkpoints/jupyter-pandas-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 2 6 | } 7 | -------------------------------------------------------------------------------- /contoh/buat-unicode.py: -------------------------------------------------------------------------------- 1 | unicode_text = u'BUDI Rahardjo' 2 | myencoded = unicode_text.encode('utf-16-le') 3 | #myencoded = unicode_text.encode('utf-16-be') 4 | 5 | a_file = open("budi-unicode.txt", "wb") 6 | a_file.write(myencoded) 7 | 8 | a_file = open("budi-unicode.txt", "r", encoding='utf-16-le') 9 | #a_file = open("budi-unicode.txt", "r", encoding='utf-16-be') 10 | # reads contents of a file 11 | contents = a_file.read() 12 | print(contents) 13 | -------------------------------------------------------------------------------- /contoh/budi-unicode.txt: -------------------------------------------------------------------------------- 1 | BUDI Rahardjo -------------------------------------------------------------------------------- /contoh/cli-args.py: -------------------------------------------------------------------------------- 1 | # contoh parsing argumen yang diberikan kepada program 2 | # beri nama skrip ini cli-args.py 3 | # cara menjalankan: 4 | # python3 cli-args.py opsi1 opsi2 opsi3 5 | # opsi bisa banyak 6 | 7 | import sys 8 | # periksa jumlah argumennya 9 | 10 | numberargs = len(sys.argv) 11 | # tanpa argumen, hasilnya akan 0 (nol) 12 | # nama skrip adalah sys.argv[0] 13 | 14 | # print argumen yang diberikan 15 | for i in range(numberargs): 16 | print(i, sys.argv[i]) 17 | 18 | -------------------------------------------------------------------------------- /contoh/cluster-create-pr.py: -------------------------------------------------------------------------------- 1 | # membuat tiga cluster 2 | # (cc) 2022, Budi Rahardjo 3 | import numpy as np 4 | import matplotlib.pyplot as plt 5 | 6 | # buat function dulu 7 | def buat_list(cx,cy): 8 | x_point.append([cx]) 9 | y_point.append([cy]) 10 | for i in range(jumlah_data): 11 | x = cx + np.random.normal(0.0,0.7) 12 | y = cy + np.random.normal(0.0,0.7) 13 | x_point.append([x]) 14 | y_point.append([y]) 15 | 16 | jumlah_data=100 17 | x_point = [] 18 | y_point = [] 19 | # cluster pertama, centroid di (10, 4,5) 20 | buat_list(10.0, 4.5) 21 | # cluster kedua, centroid di (3.5, 2.5) 22 | buat_list(3.5, 2.5) 23 | # cluster ketiga, centroid di (4.5, 8.5) 24 | buat_list(4.5, 8.5) 25 | # cluster keempat, centroid di (8, 10) 26 | buat_list(8.0,10.0) 27 | 28 | # simpan dalam bentuk CSV 29 | np.savetxt("cluster-pr.csv", np.column_stack([x_point, y_point]), fmt='%.5f', delimiter=', ') 30 | 31 | plt.plot(x_point,y_point, 'x') 32 | plt.show() 33 | -------------------------------------------------------------------------------- /contoh/cluster-create.py: -------------------------------------------------------------------------------- 1 | # membuat tiga cluster 2 | # (cc) 2022, Budi Rahardjo 3 | import numpy as np 4 | import matplotlib.pyplot as plt 5 | 6 | # buat function dulu 7 | def buat_list(cx,cy): 8 | x_point.append([cx]) 9 | y_point.append([cy]) 10 | for i in range(jumlah_data): 11 | x = cx + np.random.normal(0.0,0.7) 12 | y = cy + np.random.normal(0.0,0.7) 13 | x_point.append([x]) 14 | y_point.append([y]) 15 | 16 | jumlah_data=100 17 | x_point = [] 18 | y_point = [] 19 | # cluster pertama, centroid di (10, 4,5) 20 | buat_list(10.0, 4.5) 21 | # cluster kedua, centroid di (3.5, 2.5) 22 | buat_list(3.5, 2.5) 23 | # cluster ketiga, centroid di (4.5, 8.5) 24 | buat_list(4.5, 8.5) 25 | 26 | # simpan dalam bentuk CSV 27 | np.savetxt("cluster.csv", np.column_stack([x_point, y_point]), fmt='%.5f', delimiter=', ') 28 | 29 | plt.plot(x_point,y_point, 'x') 30 | plt.show() 31 | -------------------------------------------------------------------------------- /contoh/cluster-pr.csv: -------------------------------------------------------------------------------- 1 | 10.00000, 4.50000 2 | 9.41587, 4.81410 3 | 9.81030, 5.06881 4 | 9.29875, 4.19161 5 | 9.49183, 4.70544 6 | 9.83588, 3.39376 7 | 10.83643, 4.77336 8 | 10.06674, 4.57448 9 | 8.74279, 4.78515 10 | 9.35499, 4.51321 11 | 9.81190, 5.09608 12 | 8.82035, 5.21356 13 | 10.29436, 5.06016 14 | 11.22557, 4.99529 15 | 10.84887, 5.70877 16 | 9.73981, 4.49641 17 | 10.46950, 4.75495 18 | 10.20337, 4.94719 19 | 9.52437, 4.07283 20 | 9.51791, 4.12213 21 | 10.15633, 4.06187 22 | 9.65205, 4.83593 23 | 8.70010, 5.01392 24 | 7.89011, 4.31775 25 | 8.70910, 5.13834 26 | 8.85364, 5.38696 27 | 10.47142, 3.53792 28 | 10.38331, 4.95585 29 | 10.42687, 2.73562 30 | 9.59253, 4.77692 31 | 9.67338, 4.66762 32 | 9.43795, 4.81368 33 | 9.89178, 4.52123 34 | 8.88146, 5.49442 35 | 11.06773, 5.30175 36 | 10.06690, 3.94570 37 | 10.21904, 4.03868 38 | 10.34892, 4.69458 39 | 10.44872, 5.19913 40 | 10.32961, 5.23560 41 | 10.24140, 4.08238 42 | 10.75237, 3.44136 43 | 10.25336, 5.51809 44 | 9.08585, 4.45246 45 | 9.62484, 4.72838 46 | 9.78113, 5.48420 47 | 9.38695, 3.53556 48 | 10.66681, 5.17310 49 | 9.83433, 4.41628 50 | 11.81769, 5.07807 51 | 9.98773, 4.86866 52 | 10.08473, 4.42027 53 | 10.80355, 5.18345 54 | 9.67748, 3.08905 55 | 9.45052, 4.17682 56 | 10.11826, 3.73577 57 | 9.90742, 3.62724 58 | 8.28807, 5.50893 59 | 9.56758, 5.78468 60 | 9.10720, 4.13289 61 | 10.06609, 5.14326 62 | 10.53387, 5.40565 63 | 9.25325, 5.03343 64 | 11.17707, 4.79934 65 | 10.76520, 5.41146 66 | 9.95121, 5.01296 67 | 9.95278, 5.05914 68 | 9.85917, 5.45490 69 | 10.68400, 4.55555 70 | 9.95140, 4.41819 71 | 9.64016, 4.73204 72 | 8.90832, 4.83154 73 | 10.65411, 2.68326 74 | 10.06653, 4.33369 75 | 9.14732, 4.77792 76 | 10.53926, 4.29093 77 | 10.50286, 4.43275 78 | 10.39831, 5.18723 79 | 9.62992, 3.95625 80 | 11.25501, 4.84984 81 | 9.81108, 4.17732 82 | 10.37821, 4.37636 83 | 10.42748, 4.93342 84 | 9.34587, 5.18745 85 | 9.82830, 3.96368 86 | 10.99296, 4.79972 87 | 9.85772, 4.25477 88 | 10.12979, 4.91410 89 | 10.63976, 6.22230 90 | 10.08158, 4.55784 91 | 10.67738, 4.90493 92 | 9.39512, 4.39288 93 | 9.49101, 4.36491 94 | 9.76829, 5.48193 95 | 9.55938, 5.17951 96 | 10.97726, 4.56686 97 | 9.51755, 4.67298 98 | 10.12357, 5.22536 99 | 8.71491, 4.00882 100 | 9.82314, 4.90009 101 | 10.60581, 4.06268 102 | 3.50000, 2.50000 103 | 3.49205, 2.58344 104 | 3.16995, 3.32249 105 | 3.44039, 2.93480 106 | 4.22190, 3.21492 107 | 3.23349, 1.81807 108 | 3.37958, 3.72829 109 | 4.43501, 2.18436 110 | 2.87444, 3.07416 111 | 3.05064, 2.07885 112 | 3.26336, 2.43860 113 | 4.14698, 2.75008 114 | 3.88352, 2.19543 115 | 4.20004, 2.68913 116 | 3.04450, 2.88132 117 | 4.67000, 1.91806 118 | 3.42269, 1.08674 119 | 3.47384, 2.98127 120 | 4.15384, 2.87768 121 | 4.27955, 2.21058 122 | 4.92435, 1.24951 123 | 2.85570, 2.10343 124 | 5.25835, 2.36945 125 | 3.62167, 2.20239 126 | 4.40828, 2.03351 127 | 3.89208, 2.43277 128 | 2.81373, 2.28333 129 | 2.77579, 2.68106 130 | 3.62907, 3.20569 131 | 3.22727, 2.84860 132 | 3.33676, 2.78451 133 | 3.66767, 2.10158 134 | 3.93983, 2.99626 135 | 3.81342, 2.55657 136 | 2.72814, 1.60829 137 | 3.01660, 2.79438 138 | 2.12654, 3.04538 139 | 3.58134, 2.86417 140 | 3.72821, 2.28751 141 | 2.14889, 1.07717 142 | 4.00478, 3.41223 143 | 3.23944, 3.61887 144 | 3.39728, 2.84519 145 | 5.09784, 1.85576 146 | 3.54780, 1.58498 147 | 3.12419, 3.18250 148 | 3.46965, 3.04068 149 | 2.74281, 2.82751 150 | 4.40374, 2.61071 151 | 3.45828, 0.93253 152 | 3.32931, 3.06834 153 | 2.93082, 2.34747 154 | 4.04470, 1.09096 155 | 2.29673, 3.03243 156 | 4.21926, 1.48656 157 | 2.74580, 3.10979 158 | 4.14730, 2.85539 159 | 3.61154, 1.69341 160 | 3.40667, 2.68489 161 | 3.91531, 1.78449 162 | 4.50869, 1.42927 163 | 3.97300, 2.73026 164 | 2.95656, 2.00720 165 | 3.23340, 1.71962 166 | 2.77065, 3.66267 167 | 3.49474, 2.53085 168 | 3.42537, 2.10854 169 | 3.95580, 2.61199 170 | 4.93104, 3.83865 171 | 3.76359, 3.37814 172 | 3.48240, 0.75318 173 | 3.14432, 2.90578 174 | 2.31788, 1.75831 175 | 3.16403, 3.43953 176 | 4.80792, 2.31907 177 | 3.85894, 1.79858 178 | 4.19866, 2.99904 179 | 4.57262, 2.15791 180 | 2.57932, 3.80574 181 | 4.60083, 1.80843 182 | 2.50607, 2.87264 183 | 3.18236, 2.41026 184 | 4.24744, 2.94018 185 | 4.83563, 3.92866 186 | 3.34329, 2.21948 187 | 2.54350, 2.57872 188 | 3.29788, 2.89106 189 | 4.46242, 2.56563 190 | 3.50512, 2.35637 191 | 4.11393, 3.43697 192 | 3.16403, 3.14140 193 | 3.38932, 2.57524 194 | 4.81492, 2.21261 195 | 3.49787, 1.59912 196 | 3.01551, 3.57136 197 | 3.30039, 1.76367 198 | 4.49316, 1.76409 199 | 2.63357, 3.08562 200 | 2.32754, 2.20831 201 | 3.63383, 1.79995 202 | 3.10404, 1.04454 203 | 4.50000, 8.50000 204 | 5.27075, 8.30037 205 | 3.74798, 9.09945 206 | 4.30720, 7.88676 207 | 3.85961, 9.10725 208 | 4.79830, 8.38825 209 | 4.64160, 7.75830 210 | 4.68796, 7.40634 211 | 3.42678, 7.07607 212 | 4.50733, 8.75442 213 | 4.96767, 9.15128 214 | 5.45741, 7.58491 215 | 4.85342, 7.98078 216 | 5.33524, 8.23926 217 | 4.00947, 8.75812 218 | 4.22871, 8.64096 219 | 3.51437, 9.22854 220 | 4.03357, 8.80279 221 | 5.10551, 8.56618 222 | 4.54133, 7.66727 223 | 5.56740, 7.66043 224 | 4.84698, 8.79200 225 | 4.42126, 9.08614 226 | 4.72342, 10.29178 227 | 4.45622, 8.00204 228 | 3.96488, 9.01199 229 | 4.54555, 9.25134 230 | 5.02693, 8.27057 231 | 5.71189, 8.26330 232 | 5.37206, 8.03322 233 | 4.87209, 9.50967 234 | 4.24275, 8.02899 235 | 3.49043, 9.48930 236 | 5.56807, 7.36307 237 | 5.02178, 9.44055 238 | 4.47635, 7.86842 239 | 4.70900, 7.97452 240 | 4.14436, 8.90784 241 | 5.64153, 7.88183 242 | 4.61279, 7.55744 243 | 4.01790, 9.31874 244 | 5.11054, 9.78637 245 | 4.16828, 9.66407 246 | 4.28365, 8.66359 247 | 4.28855, 7.13426 248 | 5.32942, 8.51538 249 | 5.25184, 8.79485 250 | 4.49626, 9.14022 251 | 4.54404, 8.17754 252 | 4.69285, 9.80471 253 | 3.80401, 8.74121 254 | 4.62507, 7.08682 255 | 4.79210, 8.68831 256 | 5.04863, 7.80150 257 | 4.51372, 8.05333 258 | 5.05061, 9.21505 259 | 4.87642, 9.52688 260 | 4.71353, 8.28207 261 | 4.06515, 8.21299 262 | 5.03634, 9.43388 263 | 5.01144, 8.97385 264 | 4.46905, 8.43346 265 | 4.69211, 8.73488 266 | 5.76172, 8.95959 267 | 4.53268, 9.07179 268 | 4.18293, 10.11697 269 | 5.56473, 8.00771 270 | 5.33757, 8.15100 271 | 4.38209, 9.07285 272 | 4.89916, 8.61286 273 | 4.71308, 7.08819 274 | 4.62515, 8.76445 275 | 4.18643, 9.26227 276 | 4.74852, 8.25442 277 | 3.91629, 8.94362 278 | 5.22114, 8.58713 279 | 5.46454, 8.06823 280 | 4.43232, 9.44413 281 | 4.33257, 8.83029 282 | 4.68479, 8.15382 283 | 3.16339, 8.81774 284 | 3.07819, 7.83786 285 | 4.51694, 8.71222 286 | 4.58946, 9.10195 287 | 5.02581, 7.96567 288 | 5.23131, 9.51128 289 | 4.43769, 9.57133 290 | 4.32335, 7.52765 291 | 6.03362, 8.78729 292 | 4.70024, 8.96155 293 | 5.69548, 7.78485 294 | 4.52811, 9.17172 295 | 3.53519, 8.90728 296 | 5.03698, 9.55601 297 | 3.90760, 10.59939 298 | 3.66445, 7.22368 299 | 4.04514, 8.79441 300 | 3.82465, 8.14012 301 | 4.06352, 9.01735 302 | 4.86971, 6.29804 303 | 3.09480, 8.17545 304 | 8.00000, 10.00000 305 | 8.25002, 8.80072 306 | 7.77208, 10.00862 307 | 8.47593, 10.12025 308 | 8.10150, 10.11447 309 | 7.40617, 8.94041 310 | 8.58416, 9.82116 311 | 8.12592, 9.95875 312 | 8.23205, 9.33827 313 | 6.95097, 9.35019 314 | 7.47574, 11.21985 315 | 8.87766, 10.36165 316 | 9.09820, 10.76391 317 | 8.52926, 10.42309 318 | 7.87822, 9.37235 319 | 8.17549, 10.19358 320 | 7.31656, 10.86908 321 | 9.41068, 10.52890 322 | 7.73099, 10.09629 323 | 6.98288, 11.00662 324 | 8.91641, 9.66734 325 | 7.71840, 10.47877 326 | 8.06625, 9.83226 327 | 7.78761, 10.30057 328 | 8.15285, 10.39000 329 | 7.72293, 9.82007 330 | 7.75249, 9.93496 331 | 7.78728, 10.01597 332 | 6.90301, 11.12875 333 | 7.36465, 9.75515 334 | 9.05289, 10.19487 335 | 7.30787, 9.97243 336 | 9.05162, 8.98629 337 | 8.67917, 10.73311 338 | 8.53209, 10.38811 339 | 8.03332, 9.80477 340 | 7.64462, 10.66503 341 | 7.19303, 10.40725 342 | 8.08944, 11.44903 343 | 7.49530, 10.89648 344 | 8.24002, 9.46821 345 | 8.34174, 8.71084 346 | 8.04967, 9.45440 347 | 7.47330, 9.36729 348 | 6.71347, 9.64506 349 | 8.59591, 9.69203 350 | 6.97703, 12.12708 351 | 8.27916, 10.94532 352 | 8.24960, 9.30743 353 | 8.60149, 10.38927 354 | 7.67130, 10.22757 355 | 7.83662, 9.42452 356 | 6.87633, 10.35607 357 | 8.78679, 10.84913 358 | 7.81094, 9.68986 359 | 8.12029, 10.18771 360 | 7.43276, 10.59674 361 | 8.80480, 9.24302 362 | 8.77025, 9.43945 363 | 9.23510, 10.69986 364 | 7.46255, 8.82102 365 | 7.28100, 10.33828 366 | 8.46405, 9.81843 367 | 8.99798, 9.55098 368 | 6.99876, 9.87294 369 | 6.13387, 8.79254 370 | 8.69936, 9.05471 371 | 8.17178, 10.40483 372 | 7.33696, 9.05128 373 | 8.38411, 10.74742 374 | 9.30642, 10.09546 375 | 8.37019, 9.83839 376 | 10.16765, 9.41630 377 | 8.24113, 10.12807 378 | 8.10447, 10.00977 379 | 9.07353, 11.00026 380 | 8.32609, 9.63004 381 | 8.95931, 9.51917 382 | 8.65230, 9.16203 383 | 8.17106, 9.46977 384 | 8.44663, 10.62600 385 | 7.44338, 8.92575 386 | 7.48046, 9.78506 387 | 7.28205, 9.87966 388 | 7.75050, 9.13579 389 | 7.38871, 9.85868 390 | 7.78917, 9.85649 391 | 6.71500, 9.81694 392 | 8.73765, 9.41722 393 | 8.21309, 10.13109 394 | 7.66713, 10.96391 395 | 8.20412, 9.60109 396 | 8.02955, 11.63562 397 | 7.68578, 9.36533 398 | 7.65794, 9.60175 399 | 6.93829, 10.05384 400 | 7.86936, 8.88278 401 | 8.51526, 9.57423 402 | 7.56316, 10.43750 403 | 8.50814, 10.11480 404 | 9.05865, 10.34269 405 | -------------------------------------------------------------------------------- /contoh/cluster.csv: -------------------------------------------------------------------------------- 1 | 10.00000, 4.50000 2 | 9.97620, 3.93898 3 | 11.08496, 4.98229 4 | 9.48476, 5.88355 5 | 9.74898, 5.09208 6 | 9.95355, 4.21591 7 | 10.17415, 4.26569 8 | 10.13014, 3.21299 9 | 9.42241, 5.19947 10 | 8.57572, 3.59804 11 | 11.87546, 4.18848 12 | 10.49596, 3.92326 13 | 11.02033, 4.91208 14 | 9.63783, 4.34924 15 | 9.44750, 4.99188 16 | 9.31937, 5.81269 17 | 9.50862, 5.10549 18 | 9.67732, 3.76044 19 | 8.96448, 3.76851 20 | 9.84539, 3.82133 21 | 9.46617, 2.87636 22 | 10.45414, 3.89119 23 | 11.58089, 3.56740 24 | 8.86838, 5.51698 25 | 9.48118, 4.89991 26 | 10.32704, 5.15207 27 | 8.73547, 4.35834 28 | 10.69386, 4.11552 29 | 10.66127, 3.72779 30 | 10.93004, 4.33246 31 | 9.36315, 3.44847 32 | 9.59415, 3.23239 33 | 10.09275, 4.68169 34 | 10.64211, 5.79093 35 | 10.73254, 3.82954 36 | 9.98063, 3.16443 37 | 8.51160, 5.02078 38 | 11.11216, 5.12174 39 | 10.20884, 6.50778 40 | 11.34925, 4.90857 41 | 10.01715, 3.14872 42 | 10.27035, 5.05074 43 | 10.40762, 5.48779 44 | 10.42348, 4.47482 45 | 9.99362, 4.99476 46 | 9.77644, 3.89562 47 | 11.21046, 4.72919 48 | 10.17373, 6.22445 49 | 10.00275, 4.62014 50 | 9.65830, 4.30904 51 | 9.72316, 4.73423 52 | 9.96638, 5.83196 53 | 9.08468, 4.25387 54 | 9.81588, 4.48921 55 | 10.36555, 3.18942 56 | 11.21292, 3.86220 57 | 9.73515, 4.43495 58 | 9.24982, 3.71901 59 | 9.92542, 3.88483 60 | 10.30121, 5.81266 61 | 11.17402, 4.12641 62 | 10.70436, 4.94607 63 | 9.40752, 4.67612 64 | 10.59797, 4.57200 65 | 10.97744, 4.79301 66 | 10.74263, 3.45130 67 | 10.60215, 4.93681 68 | 10.57053, 4.94300 69 | 10.90355, 5.04290 70 | 10.05239, 5.52868 71 | 10.30762, 3.63596 72 | 10.00693, 3.20729 73 | 9.63535, 3.87652 74 | 9.34748, 5.19428 75 | 10.64074, 5.11796 76 | 9.71275, 4.50164 77 | 9.25588, 5.56291 78 | 11.65769, 3.77518 79 | 9.14009, 5.03735 80 | 8.28471, 3.69094 81 | 10.78544, 5.04287 82 | 10.19950, 3.24433 83 | 10.04485, 4.66058 84 | 9.09875, 4.97632 85 | 10.68421, 5.07132 86 | 8.36054, 4.80208 87 | 9.36182, 3.82976 88 | 8.54584, 4.12653 89 | 10.09968, 4.11080 90 | 11.14172, 5.18939 91 | 10.40268, 4.56565 92 | 9.29879, 3.83384 93 | 9.99383, 5.84061 94 | 9.66399, 5.22646 95 | 10.05400, 4.99578 96 | 11.62190, 4.96069 97 | 9.68367, 3.61751 98 | 10.01773, 5.10245 99 | 10.79020, 4.88714 100 | 9.63747, 3.74082 101 | 9.99116, 4.26510 102 | 3.50000, 2.50000 103 | 2.95409, 2.53477 104 | 3.40006, 1.45626 105 | 3.61374, 2.63853 106 | 2.64088, 3.31095 107 | 5.39942, 2.63827 108 | 3.81758, 2.41556 109 | 3.46279, 2.02535 110 | 3.13660, 0.38332 111 | 3.90178, 1.74790 112 | 2.77112, 2.39386 113 | 2.50784, 3.15266 114 | 2.00350, 1.60053 115 | 2.20494, 2.86912 116 | 3.32560, 1.23481 117 | 3.23684, 1.16236 118 | 3.05530, 3.12174 119 | 3.68289, 2.88017 120 | 3.68364, 1.87165 121 | 4.03630, 1.42907 122 | 2.68335, 1.86203 123 | 4.35513, 1.55453 124 | 2.84979, 2.39550 125 | 3.92363, 2.68802 126 | 3.06128, 2.53415 127 | 3.00254, 2.93813 128 | 4.26605, 2.42667 129 | 3.25406, 1.07554 130 | 3.34007, 2.27544 131 | 3.04625, 2.81591 132 | 3.85427, 2.60225 133 | 5.44130, 2.08989 134 | 4.17435, 1.55156 135 | 3.86254, 2.83402 136 | 2.82688, 2.04755 137 | 3.09479, 1.80454 138 | 3.22742, 2.32922 139 | 3.42282, 2.35542 140 | 4.00937, 2.26742 141 | 3.23210, 2.74109 142 | 3.22473, 1.54061 143 | 3.40931, 3.15460 144 | 2.27787, 3.04104 145 | 2.99118, 1.40402 146 | 2.64765, 2.74764 147 | 3.93887, 1.94660 148 | 4.47394, 2.97199 149 | 3.41876, 2.34388 150 | 5.31836, 2.19270 151 | 3.26087, 2.25322 152 | 2.16791, 2.09129 153 | 4.17843, 3.48747 154 | 2.09497, 2.59307 155 | 4.26541, 1.40643 156 | 2.92516, 2.88729 157 | 3.16655, 1.57177 158 | 2.81319, 2.15117 159 | 4.08753, 2.57336 160 | 2.95364, 1.96449 161 | 2.59140, 1.24028 162 | 4.41801, 1.95480 163 | 3.25169, 3.37421 164 | 4.73012, 2.03866 165 | 3.20134, 2.85828 166 | 3.66642, 2.05248 167 | 3.73937, 3.50156 168 | 3.94072, 4.06444 169 | 3.71448, 2.18998 170 | 2.65194, 2.94526 171 | 3.72115, 1.45348 172 | 2.93304, 2.23757 173 | 4.43726, 1.69259 174 | 3.55079, 2.75042 175 | 4.34989, 2.33326 176 | 3.98675, 3.41358 177 | 4.11717, 0.94613 178 | 2.85753, 2.07897 179 | 4.13475, 2.23416 180 | 2.70141, 2.40592 181 | 3.26515, 2.53692 182 | 4.37382, 2.04580 183 | 2.66929, 3.77576 184 | 4.86765, 1.72423 185 | 3.76766, 2.60221 186 | 2.62686, 0.91816 187 | 2.75856, 1.75156 188 | 4.23356, 3.05463 189 | 4.60754, 2.25332 190 | 3.71576, 2.25263 191 | 4.90742, 1.68723 192 | 3.05268, 2.26475 193 | 3.06972, 3.08918 194 | 3.01579, 2.65103 195 | 4.52973, 2.68525 196 | 3.06760, 4.30227 197 | 2.05752, 1.36913 198 | 3.04448, 3.63564 199 | 4.16458, 2.71583 200 | 3.36303, 1.68708 201 | 3.21724, 1.92966 202 | 3.24577, 3.06554 203 | 4.50000, 8.50000 204 | 4.59521, 8.20705 205 | 3.60202, 7.69619 206 | 5.19997, 8.46583 207 | 4.55657, 8.28547 208 | 3.26016, 8.92985 209 | 3.34471, 9.40164 210 | 4.68927, 9.57066 211 | 3.15346, 7.31901 212 | 3.92207, 9.72326 213 | 5.17241, 7.75854 214 | 4.45755, 8.65305 215 | 4.61204, 8.67052 216 | 2.92542, 8.47667 217 | 4.45252, 8.15784 218 | 3.37544, 8.56188 219 | 5.01796, 8.66044 220 | 4.27302, 7.81577 221 | 4.27252, 7.54671 222 | 4.92267, 9.62544 223 | 4.64218, 8.53864 224 | 4.78935, 8.02276 225 | 3.92368, 8.63800 226 | 4.00753, 9.36801 227 | 3.96877, 10.62082 228 | 5.09490, 8.41696 229 | 3.63673, 8.56430 230 | 3.49923, 8.70101 231 | 5.42099, 9.09179 232 | 3.54369, 9.12629 233 | 5.03345, 8.44280 234 | 4.46519, 8.56739 235 | 4.50263, 6.64942 236 | 5.46471, 8.09224 237 | 4.94107, 8.69271 238 | 4.40711, 8.00165 239 | 5.05191, 8.48807 240 | 3.17509, 8.13911 241 | 5.12423, 7.70451 242 | 3.57536, 8.15083 243 | 4.63217, 7.64441 244 | 3.99480, 8.30187 245 | 4.91322, 7.87998 246 | 3.69324, 7.49943 247 | 3.42778, 8.64943 248 | 4.52628, 8.03354 249 | 5.10500, 9.26306 250 | 4.24882, 7.42494 251 | 4.60749, 8.48214 252 | 3.94137, 7.71841 253 | 2.74370, 8.20845 254 | 4.77318, 8.38402 255 | 4.83395, 7.99157 256 | 5.83868, 8.04741 257 | 3.90633, 9.70501 258 | 3.48290, 8.72920 259 | 4.67427, 8.00484 260 | 3.74102, 7.80985 261 | 3.61809, 8.13466 262 | 3.92974, 9.11493 263 | 3.69368, 9.08207 264 | 3.73711, 8.31309 265 | 3.32979, 8.23755 266 | 5.33120, 8.43807 267 | 4.89555, 7.59036 268 | 4.15922, 9.19766 269 | 4.21482, 8.39849 270 | 3.85727, 8.83678 271 | 3.93500, 8.39708 272 | 4.90197, 8.53808 273 | 3.37668, 8.32227 274 | 4.25624, 7.66182 275 | 5.58852, 8.30141 276 | 5.23084, 9.00531 277 | 3.70288, 7.04238 278 | 3.69878, 8.05311 279 | 5.67030, 9.10255 280 | 4.89047, 8.17757 281 | 5.21788, 8.04058 282 | 4.60797, 8.44697 283 | 3.74410, 8.04113 284 | 4.52659, 7.62503 285 | 4.16502, 8.65864 286 | 4.27532, 7.86513 287 | 3.30389, 7.78753 288 | 4.51613, 8.38290 289 | 4.50695, 8.20824 290 | 5.31293, 7.08453 291 | 4.31881, 9.06722 292 | 4.29962, 7.62723 293 | 4.91500, 7.89068 294 | 3.47118, 8.73460 295 | 3.63024, 8.85592 296 | 5.07821, 8.52794 297 | 4.14832, 8.77354 298 | 3.63092, 8.91442 299 | 5.04918, 8.38052 300 | 3.65602, 8.27896 301 | 3.71756, 8.67284 302 | 4.47460, 8.48576 303 | 4.76238, 8.69781 304 | -------------------------------------------------------------------------------- /contoh/cobahash.py: -------------------------------------------------------------------------------- 1 | # 2 | # Contoh fungsi hash 3 | 4 | import hashlib 5 | h = hashlib.sha256("beli 10000\n") 6 | print h.hexdigest() 7 | -------------------------------------------------------------------------------- /contoh/cobaplot-xy.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | f = open('data.txt', 'r') 5 | 6 | x = [] 7 | y = [] 8 | while True: 9 | line = f. readline() 10 | if not line: 11 | break 12 | line = line.rstrip() 13 | a,b = line.split(',') 14 | x.append(int(a)) 15 | y.append(int(b)) 16 | 17 | plt.plot(x,y,'o',label='Random Data') 18 | plt.legend() 19 | plt.show() 20 | -------------------------------------------------------------------------------- /contoh/cobaplot.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | a = 0.25 5 | b = 0.75 6 | jumlah_titik = 300 7 | # buat dua list yang masih kosong 8 | x_point = [] 9 | y_point = [] 10 | for i in range(jumlah_titik): 11 | x = np.random.normal(0.0,0.4) 12 | y = a*x + b + np.random.normal(0.0,0.1) 13 | x_point.append([x]) 14 | y_point.append([y]) 15 | plt.plot(x_point,y_point,'o',label='Random Data') 16 | plt.legend() 17 | plt.show() 18 | -------------------------------------------------------------------------------- /contoh/data.txt: -------------------------------------------------------------------------------- 1 | 1, 10 2 | 2, 12 3 | 3, 9 4 | 4, 7 5 | 5, 10 6 | 6, 2 7 | 7, 9 8 | 8, 3 9 | 9, 10 10 | 10, 9 11 | 11, 9 12 | 12, 10 13 | 13, 9 14 | 14, 10 15 | 15, 9 16 | -------------------------------------------------------------------------------- /contoh/input.py: -------------------------------------------------------------------------------- 1 | 2 | # ini untuk Python 2.7 3 | # gunakan raw_input 4 | nama = raw_input("Masukkan nama Anda: ") 5 | print "Selamat pagi,", nama 6 | 7 | # for loop bisa menggunakan elemen dari string 8 | # tidak harus indeks angka 9 | for i in nama: 10 | print i 11 | 12 | # associative array: hitung jumlah huruf dan spasi 13 | huruf = {} # inisialisasi 14 | for key in nama: 15 | if key in huruf: 16 | huruf[key] += 1 17 | else: 18 | huruf[key]=1 19 | # tampilkan hasil python 2.7 20 | # sorted() agar key-nya diurutkan 21 | # for python 3.* use this: for key, value in d.items(): 22 | for key, value in sorted(huruf.iteritems()): 23 | print key, value 24 | -------------------------------------------------------------------------------- /contoh/jupyter-json.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Brian\n", 13 | "Seattle\n" 14 | ] 15 | } 16 | ], 17 | "source": [ 18 | "import json\n", 19 | " \n", 20 | "json_data = '{\"name\": \"Brian\", \"city\": \"Seattle\"}'\n", 21 | "python_obj = json.loads(json_data)\n", 22 | "print(python_obj[\"name\"])\n", 23 | "print(python_obj[\"city\"])" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [] 32 | } 33 | ], 34 | "metadata": { 35 | "kernelspec": { 36 | "display_name": "Python 3", 37 | "language": "python", 38 | "name": "python3" 39 | }, 40 | "language_info": { 41 | "codemirror_mode": { 42 | "name": "ipython", 43 | "version": 3 44 | }, 45 | "file_extension": ".py", 46 | "mimetype": "text/x-python", 47 | "name": "python", 48 | "nbconvert_exporter": "python", 49 | "pygments_lexer": "ipython3", 50 | "version": "3.6.5" 51 | } 52 | }, 53 | "nbformat": 4, 54 | "nbformat_minor": 2 55 | } 56 | -------------------------------------------------------------------------------- /contoh/jupyter-pandas.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "0 1.0\n", 13 | "1 3.0\n", 14 | "2 5.0\n", 15 | "3 7.0\n", 16 | "4 NaN\n", 17 | "5 9.0\n", 18 | "6 11.0\n", 19 | "dtype: float64\n" 20 | ] 21 | } 22 | ], 23 | "source": [ 24 | "import pandas as pd\n", 25 | "import numpy as np\n", 26 | "import matplotlib.pyplot as plt\n", 27 | "\n", 28 | "# create series\n", 29 | "ser = pd.Series([1,3,5,7,np.nan,9,11])\n", 30 | "print(ser)" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "metadata": {}, 44 | "outputs": [], 45 | "source": [] 46 | } 47 | ], 48 | "metadata": { 49 | "kernelspec": { 50 | "display_name": "Python 3", 51 | "language": "python", 52 | "name": "python3" 53 | }, 54 | "language_info": { 55 | "codemirror_mode": { 56 | "name": "ipython", 57 | "version": 3 58 | }, 59 | "file_extension": ".py", 60 | "mimetype": "text/x-python", 61 | "name": "python", 62 | "nbconvert_exporter": "python", 63 | "pygments_lexer": "ipython3", 64 | "version": "3.6.5" 65 | } 66 | }, 67 | "nbformat": 4, 68 | "nbformat_minor": 2 69 | } 70 | -------------------------------------------------------------------------------- /contoh/kmeans.py: -------------------------------------------------------------------------------- 1 | # contoh program untuk k-means 2 | import pandas as pd 3 | import matplotlib.pyplot as plt 4 | 5 | # baca data dahulu 6 | df = pd.read_csv('cluster.csv', header=None) 7 | df.columns = ['x', 'y'] 8 | #print(df) 9 | # tampilkan jika dibutuhkan 10 | df.plot.scatter(x = 'x', y='y', c='red') 11 | plt.show() 12 | 13 | # mari kita lakukan k-means clustering 14 | # silahkan diubah-ubah jumlah clusternya di variabel n_clusters 15 | from sklearn.cluster import KMeans 16 | kmeans = KMeans(n_clusters=3).fit(df) 17 | centroids = kmeans.cluster_centers_ 18 | print(centroids) 19 | 20 | # tampilkan secara visual 21 | plt.scatter(df['x'],df['y'], c=kmeans.labels_.astype(float),s=50,alpha=0.5) 22 | plt.scatter(centroids[:, 0], centroids[:, 1], c='red') 23 | plt.show() 24 | -------------------------------------------------------------------------------- /contoh/linear-regression-create.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | # persamaan y = a*x + b 4 | a = -0.3 5 | b = 0.87 6 | jumlah_titik = 300 7 | 8 | # buat dua list yang masih kosong 9 | x_point = [] 10 | y_point = [] 11 | 12 | for i in range(jumlah_titik): 13 | x = np.random.normal(0.0,0.4) 14 | y = a*x + b + np.random.normal(0.0,0.07) 15 | x_point.append([x]) 16 | y_point.append([y]) 17 | 18 | np.savetxt("linear-regression-pr.csv", np.column_stack([x_point, y_point]), fmt='%.5f', delimiter=', ') 19 | -------------------------------------------------------------------------------- /contoh/linear-regression-pr.csv: -------------------------------------------------------------------------------- 1 | -0.04674, 0.91610 2 | 0.91174, 0.59312 3 | -0.24936, 0.86903 4 | -0.40045, 1.00655 5 | -0.30737, 0.94248 6 | 0.01957, 0.87424 7 | -0.01405, 0.76813 8 | 0.71948, 0.56186 9 | 0.71368, 0.66690 10 | -0.51521, 0.97279 11 | 0.05389, 0.64961 12 | 0.02607, 0.79447 13 | -0.13521, 0.88295 14 | 0.01699, 0.91022 15 | -0.20194, 0.86898 16 | -0.22752, 1.04907 17 | 0.20460, 0.67496 18 | -0.30439, 0.94120 19 | 0.52862, 0.74254 20 | -0.30124, 0.92502 21 | -0.32020, 1.04653 22 | 0.42458, 0.76922 23 | -0.08593, 0.94725 24 | 0.32303, 0.75789 25 | -0.77991, 1.15942 26 | 0.37270, 0.82390 27 | -0.04124, 0.90010 28 | 0.12584, 0.89953 29 | -0.21950, 0.95886 30 | -0.51488, 0.98801 31 | 0.38195, 0.91918 32 | 0.50676, 0.87132 33 | 0.08249, 0.84881 34 | 0.78037, 0.73253 35 | 0.84783, 0.53449 36 | 0.57291, 0.56984 37 | 0.31334, 0.76140 38 | -0.24878, 0.92898 39 | 0.75665, 0.55169 40 | -0.42655, 1.03163 41 | 0.54952, 0.77964 42 | 0.09300, 0.80044 43 | -0.30640, 0.86723 44 | 0.17637, 0.68371 45 | 0.29821, 0.80836 46 | -0.51558, 1.09582 47 | 0.61198, 0.64697 48 | -0.37776, 0.87220 49 | -0.10260, 0.91503 50 | 0.15940, 0.79337 51 | 0.28937, 0.80368 52 | 0.25489, 0.81047 53 | -0.45017, 1.06588 54 | -0.33616, 0.95793 55 | 0.20665, 0.69559 56 | -0.06819, 0.83353 57 | -0.27514, 0.96226 58 | 0.09033, 0.81145 59 | -0.07495, 0.86320 60 | -0.59439, 1.11776 61 | -0.30759, 0.90928 62 | 0.48326, 0.76613 63 | -0.33335, 1.00309 64 | 0.08110, 0.88082 65 | -0.30392, 0.92573 66 | -0.09395, 0.74498 67 | -0.05593, 0.93566 68 | -0.08523, 0.86974 69 | 0.02759, 0.71256 70 | -0.71940, 0.99297 71 | 0.40440, 0.81081 72 | -0.01279, 0.82274 73 | -0.39675, 1.01899 74 | -0.00165, 0.89494 75 | 0.00956, 0.86264 76 | -0.07470, 0.79748 77 | -0.22888, 0.96068 78 | 0.31040, 0.72638 79 | 0.84403, 0.56356 80 | -0.25137, 0.93761 81 | 0.33078, 0.75001 82 | -0.36621, 0.90289 83 | 0.24926, 0.63805 84 | -0.14867, 0.94478 85 | -0.08994, 0.90419 86 | 0.13548, 0.95162 87 | -0.62929, 1.14109 88 | 0.42057, 0.84299 89 | 0.00564, 0.85354 90 | -0.63416, 0.96599 91 | 0.17338, 0.80776 92 | 0.28040, 0.81632 93 | -0.53092, 0.86217 94 | -0.01324, 0.82382 95 | 0.68000, 0.70468 96 | -0.17521, 0.96499 97 | -0.18692, 0.86803 98 | 0.14440, 0.74592 99 | -0.22458, 1.06548 100 | -0.28594, 0.87865 101 | -0.16112, 0.81764 102 | 0.28007, 0.75045 103 | 0.86442, 0.61530 104 | -0.06147, 0.92286 105 | -0.03634, 0.92583 106 | -0.11738, 0.81147 107 | 0.29557, 0.85870 108 | -0.08754, 0.85273 109 | -0.21800, 1.03890 110 | -0.55801, 0.95234 111 | -0.00824, 0.87044 112 | 0.11525, 0.83837 113 | 0.34599, 0.76215 114 | 0.27767, 0.85824 115 | -0.06267, 0.83449 116 | -0.83543, 1.05349 117 | 0.24074, 0.85219 118 | -0.26982, 0.93115 119 | -0.12040, 0.87637 120 | -0.14929, 0.73531 121 | 0.28582, 0.62583 122 | 0.59416, 0.54137 123 | -0.70666, 1.07952 124 | -0.16557, 0.95275 125 | 0.02913, 0.92093 126 | -0.59537, 1.13115 127 | 0.11476, 0.79188 128 | 0.10004, 0.83705 129 | -0.02952, 0.80919 130 | 0.08913, 0.83408 131 | -0.80754, 1.17795 132 | 0.16294, 0.74327 133 | 0.16570, 0.93734 134 | -0.29797, 0.99384 135 | -0.09071, 0.93265 136 | 0.23618, 0.77137 137 | 0.48137, 0.73820 138 | -0.14824, 0.94167 139 | -0.19521, 0.90273 140 | -0.57651, 1.01640 141 | -0.30163, 1.04190 142 | 0.17489, 0.83232 143 | -0.10549, 1.02759 144 | -0.12335, 0.87144 145 | -0.05494, 0.96530 146 | -0.27940, 0.86077 147 | -0.54166, 1.04696 148 | -0.15513, 0.81826 149 | -0.23349, 1.03807 150 | 0.58411, 0.77193 151 | -0.79076, 1.09513 152 | -0.11770, 1.03400 153 | -0.03619, 0.93095 154 | -0.07065, 0.89918 155 | 0.32505, 0.64338 156 | 0.28774, 0.82207 157 | -0.04081, 0.94090 158 | -0.32789, 0.96376 159 | -0.01693, 0.68971 160 | -0.35182, 1.18859 161 | -0.20793, 0.95404 162 | -0.53426, 1.08609 163 | -1.16112, 1.10743 164 | -0.32811, 0.94705 165 | -0.25065, 0.89494 166 | -0.11101, 0.95069 167 | 0.03205, 0.83828 168 | 0.77000, 0.67140 169 | 0.99162, 0.55541 170 | -0.32814, 1.03626 171 | -0.80652, 1.11533 172 | -0.31601, 1.01397 173 | -0.81366, 1.15041 174 | -0.25878, 0.97339 175 | 0.18646, 0.77755 176 | -0.49650, 0.95605 177 | 0.58514, 0.72393 178 | -0.03702, 0.80858 179 | 0.33547, 0.76531 180 | -0.28726, 0.88860 181 | -0.33938, 0.93688 182 | 0.39639, 0.84566 183 | -0.31289, 0.98504 184 | -0.58333, 1.06086 185 | -0.18553, 0.90163 186 | 0.19364, 0.83469 187 | -0.63689, 1.07017 188 | 0.31671, 0.75332 189 | -0.06250, 0.87582 190 | -0.10780, 0.86058 191 | -0.34649, 0.95338 192 | -0.14286, 0.88929 193 | -0.45358, 0.94211 194 | 0.02644, 0.88562 195 | 0.08766, 0.77162 196 | 0.52658, 0.81340 197 | 0.38482, 0.73126 198 | 0.08188, 0.95834 199 | -0.81003, 1.10759 200 | 0.60037, 0.57228 201 | 0.12198, 0.75409 202 | 0.19104, 0.82044 203 | 0.37833, 0.79352 204 | -0.01782, 0.91378 205 | -0.22405, 0.99802 206 | 0.06028, 0.86100 207 | -0.02304, 0.97695 208 | -0.74082, 1.11932 209 | -0.28440, 0.97621 210 | -0.37576, 1.11904 211 | 0.22035, 0.66698 212 | 0.15810, 0.72438 213 | 1.02116, 0.59289 214 | 0.29940, 0.82383 215 | 0.43848, 0.61297 216 | 0.13566, 0.97748 217 | -0.55489, 1.04160 218 | 0.49204, 0.75952 219 | 0.37884, 0.77313 220 | -0.03984, 0.84620 221 | -0.25658, 0.85390 222 | -0.34484, 1.13030 223 | -0.05603, 0.90016 224 | -0.96897, 1.14534 225 | -0.02130, 0.79904 226 | -0.34329, 0.96556 227 | 0.11059, 0.89196 228 | 0.07815, 0.85678 229 | 0.58607, 0.72139 230 | 0.21848, 0.78575 231 | 0.82558, 0.65328 232 | -0.64137, 0.99933 233 | -0.06195, 0.96876 234 | -0.24615, 1.01063 235 | 0.06092, 0.95058 236 | -0.18140, 0.92769 237 | 0.10484, 0.89341 238 | 0.54142, 0.69357 239 | -0.18991, 0.91498 240 | 0.10666, 0.84583 241 | 0.05497, 0.72806 242 | -0.64865, 1.08577 243 | 0.01175, 0.84134 244 | -0.11424, 0.95403 245 | -0.23777, 0.97825 246 | -0.06306, 0.82349 247 | 0.37462, 0.77137 248 | 0.32708, 0.75005 249 | 0.90526, 0.52076 250 | -0.27863, 1.05362 251 | 0.24055, 0.81588 252 | 0.88940, 0.65932 253 | -0.06480, 0.77364 254 | 0.60076, 0.65158 255 | -0.04345, 1.00074 256 | -0.26068, 0.86584 257 | 0.29982, 0.78575 258 | 0.20598, 0.78573 259 | -0.69746, 1.02064 260 | -0.58310, 0.87066 261 | 0.02185, 0.86525 262 | -0.11643, 0.97049 263 | 0.03483, 0.88405 264 | -0.35130, 0.99259 265 | 0.14907, 0.83412 266 | -0.25966, 1.00659 267 | 0.48490, 0.70826 268 | 0.49561, 0.69074 269 | -0.29864, 0.86701 270 | 0.22697, 0.89961 271 | -0.40466, 0.95447 272 | -0.07086, 0.88188 273 | -0.65064, 0.94121 274 | -0.30697, 1.06425 275 | 0.08798, 0.87863 276 | -0.66746, 1.07291 277 | 0.19277, 0.90478 278 | 0.04919, 0.88159 279 | 0.19878, 0.85596 280 | 0.32904, 0.85557 281 | 0.18225, 0.82320 282 | 0.24765, 0.70542 283 | -0.07809, 0.81244 284 | -0.36896, 0.99861 285 | -0.02402, 0.72017 286 | 0.27901, 0.76636 287 | 0.33982, 0.85792 288 | -0.03811, 0.93111 289 | -0.11922, 0.97182 290 | 0.05906, 0.83563 291 | -0.62994, 1.04929 292 | -0.13219, 0.88735 293 | 0.22734, 0.85619 294 | -0.26910, 0.91321 295 | 0.16660, 0.72336 296 | -0.11559, 1.02831 297 | -0.46274, 1.01275 298 | -0.17488, 0.90069 299 | 0.55521, 0.66351 300 | 0.70393, 0.57346 301 | -------------------------------------------------------------------------------- /contoh/linear-regression.csv: -------------------------------------------------------------------------------- 1 | 0.26268, 4.79869 2 | -0.10326, 3.75270 3 | 0.47369, 5.40283 4 | 0.63061, 5.77021 5 | 0.49303, 5.39906 6 | -0.13602, 3.73030 7 | 0.35461, 5.15869 8 | -0.27667, 3.13630 9 | 0.38889, 5.16371 10 | -0.03652, 3.96305 11 | -0.08549, 3.73098 12 | -0.14339, 3.60448 13 | -0.40935, 2.85136 14 | -0.19138, 3.46331 15 | 0.30223, 5.01047 16 | 0.87902, 6.59208 17 | 0.01746, 4.19957 18 | 0.85380, 6.60825 19 | 0.03543, 3.87411 20 | 0.96219, 6.97734 21 | 0.25147, 4.77091 22 | 0.13138, 4.43527 23 | -0.30226, 3.00274 24 | -0.43418, 2.67201 25 | 0.65047, 6.01440 26 | 0.20348, 4.66585 27 | -0.21597, 3.42967 28 | 0.22242, 4.50448 29 | 0.77315, 6.10783 30 | -0.10144, 3.88367 31 | 0.15040, 4.54354 32 | 0.11302, 4.23411 33 | -0.29847, 3.13470 34 | 0.46390, 5.34932 35 | 0.44915, 5.24917 36 | -0.00117, 3.86921 37 | 0.35078, 5.05079 38 | -0.66644, 2.02056 39 | -0.53404, 2.56879 40 | -0.33559, 2.96054 41 | 0.09651, 4.35934 42 | -0.25138, 3.24075 43 | 0.11559, 4.43062 44 | 0.57264, 5.63127 45 | -0.59765, 2.21741 46 | -0.41512, 2.73557 47 | -0.10639, 3.55208 48 | 0.21601, 4.71607 49 | -0.50906, 2.60312 50 | 0.29597, 4.80048 51 | -0.19687, 3.49123 52 | -0.41821, 2.77148 53 | -0.38244, 2.80972 54 | 0.32837, 4.90988 55 | 0.13461, 4.48706 56 | -0.34202, 2.83263 57 | 0.38027, 5.09947 58 | -0.31354, 3.20043 59 | -0.25234, 3.19828 60 | 0.56315, 5.65308 61 | 0.33593, 5.05972 62 | 0.22744, 4.75220 63 | 0.06159, 4.07217 64 | -0.14498, 3.62946 65 | -0.30799, 3.04289 66 | 0.30786, 4.93812 67 | 0.13315, 4.23513 68 | -0.26115, 3.21210 69 | -0.37305, 2.93426 70 | -0.67712, 2.03095 71 | -0.24703, 3.36392 72 | 0.30304, 4.76647 73 | 0.11097, 4.20172 74 | 0.22313, 4.78996 75 | -0.93950, 1.27520 76 | 0.04233, 4.08923 77 | -0.29541, 3.16599 78 | -0.17329, 3.34106 79 | -0.73083, 1.84779 80 | -0.42792, 2.76371 81 | -0.49670, 2.46418 82 | -0.02982, 3.90360 83 | 0.52279, 5.59443 84 | 0.03297, 4.06426 85 | 0.41887, 5.41556 86 | -0.13759, 3.60397 87 | -0.22122, 3.34224 88 | -0.25512, 3.30704 89 | -0.42284, 2.72625 90 | -0.05762, 3.82141 91 | 0.06092, 4.11888 92 | -0.77719, 1.59685 93 | 0.07652, 4.13887 94 | 0.23321, 4.51802 95 | 0.48547, 5.55480 96 | 0.50379, 5.36885 97 | 0.03873, 4.16690 98 | 0.24026, 4.77270 99 | -0.82577, 1.40577 100 | -0.12661, 3.74210 101 | 0.03852, 4.12523 102 | 0.27410, 4.74777 103 | -0.19394, 3.48231 104 | 0.01723, 4.06440 105 | -0.19194, 3.32531 106 | 0.18208, 4.63094 107 | 0.16790, 4.68839 108 | 0.72156, 6.42951 109 | 0.16308, 4.55147 110 | 0.05093, 4.18202 111 | -0.29435, 3.19220 112 | -0.22623, 3.21021 113 | -0.03834, 4.00517 114 | -0.68248, 1.88358 115 | 0.70984, 6.02431 116 | -0.01173, 3.99123 117 | -0.05929, 3.70809 118 | -0.24936, 3.18801 119 | 0.15098, 4.23514 120 | 0.06839, 4.09555 121 | 0.17660, 4.49804 122 | -0.46592, 2.82141 123 | 0.36528, 5.27130 124 | 0.22640, 4.58272 125 | -0.95238, 1.33838 126 | -0.07297, 3.73721 127 | -0.17664, 3.36769 128 | -0.48406, 2.58174 129 | 0.44308, 5.21757 130 | -0.72296, 1.79866 131 | 0.57138, 5.60370 132 | -0.07834, 3.74400 133 | 0.41578, 5.27495 134 | -0.27873, 3.23948 135 | -0.31732, 3.25908 136 | -0.17517, 3.42373 137 | 0.01356, 4.05231 138 | 0.70722, 6.08635 139 | -0.00390, 3.87948 140 | -0.25124, 3.36430 141 | -0.59984, 2.21206 142 | 0.42276, 5.32359 143 | 0.56642, 5.96238 144 | 0.72834, 6.21166 145 | -0.20338, 3.42891 146 | -0.68384, 1.94760 147 | 0.53647, 5.59278 148 | -0.43063, 2.53122 149 | 0.51251, 5.43907 150 | -0.97306, 1.00657 151 | 0.40730, 5.19987 152 | 0.50533, 5.65716 153 | 0.49327, 5.70201 154 | -0.24515, 3.27815 155 | -0.34608, 2.97582 156 | 0.12128, 4.37101 157 | 0.66162, 6.00732 158 | 1.09097, 7.36545 159 | 0.13394, 4.43594 160 | 0.45983, 5.59233 161 | 0.22874, 4.62362 162 | -0.10179, 3.78870 163 | -0.39215, 2.99120 164 | -0.04842, 3.84748 165 | 0.57093, 5.56382 166 | -0.51660, 2.49277 167 | 0.74786, 6.25235 168 | -0.26636, 3.10931 169 | -0.73187, 1.81627 170 | 0.06230, 4.05069 171 | -0.20781, 3.27175 172 | -0.29895, 3.12377 173 | 0.33159, 5.02112 174 | 0.12463, 4.28720 175 | -0.03185, 4.00604 176 | -0.13705, 3.61615 177 | 0.23083, 4.74292 178 | -0.08734, 3.81211 179 | -0.00223, 3.94375 180 | -0.33487, 2.82886 181 | -0.09510, 3.64524 182 | 0.96880, 6.83748 183 | 0.05959, 4.20586 184 | -0.06423, 3.80969 185 | -0.36425, 2.80512 186 | 0.20980, 4.68890 187 | 0.50007, 5.43520 188 | -0.08922, 3.86820 189 | 0.23492, 4.60228 190 | -0.28750, 3.04053 191 | 0.16164, 4.37398 192 | 0.63895, 5.96566 193 | -0.64509, 2.02875 194 | 0.63870, 6.02546 195 | -0.22794, 3.44589 196 | 0.46310, 5.45834 197 | 0.82019, 6.60084 198 | -0.22242, 3.39009 199 | 0.26368, 4.92079 200 | 0.31157, 4.79945 201 | 0.78198, 6.31493 202 | 0.06945, 4.06558 203 | -0.11027, 3.81893 204 | 0.59516, 5.79891 205 | 0.12114, 4.42589 206 | -0.08210, 3.78942 207 | 0.42485, 5.20911 208 | 0.12872, 4.19950 209 | 0.84143, 6.36565 210 | 0.17878, 4.65125 211 | 0.30740, 4.85555 212 | 0.63917, 5.90443 213 | 0.66945, 5.90753 214 | 0.00013, 3.87221 215 | 0.15339, 4.24955 216 | -0.19526, 3.43433 217 | -0.82808, 1.62826 218 | 0.69978, 6.12167 219 | 0.47431, 5.35169 220 | -0.01791, 3.99589 221 | -0.10143, 3.77185 222 | -0.17407, 3.33438 223 | -0.73758, 1.84830 224 | -0.17159, 3.33599 225 | 0.40512, 5.20749 226 | 0.34272, 5.14197 227 | 0.30036, 4.92015 228 | -0.12728, 3.65416 229 | -0.10611, 3.70414 230 | 0.23719, 4.60081 231 | -0.33366, 3.08765 232 | 0.10750, 4.34235 233 | 0.01514, 4.08075 234 | -0.02575, 3.90771 235 | -0.62114, 2.16036 236 | 0.38981, 5.20322 237 | -0.11895, 3.59410 238 | -0.21347, 3.41914 239 | 0.23392, 4.77160 240 | -0.21609, 3.40672 241 | -0.21133, 3.26110 242 | 0.50701, 5.47566 243 | -0.60458, 2.23879 244 | -0.35081, 2.84099 245 | 0.29246, 4.77280 246 | 0.13201, 4.40617 247 | -0.36835, 2.90525 248 | -0.36843, 2.97988 249 | -0.59624, 2.17792 250 | -0.00495, 3.97290 251 | -0.05307, 3.52118 252 | 0.60570, 5.70064 253 | -0.05325, 3.78079 254 | -0.03922, 3.89775 255 | 0.62424, 5.89655 256 | -0.14403, 3.55454 257 | 0.27756, 4.68977 258 | -0.19172, 3.19451 259 | 0.61938, 5.93501 260 | -0.16923, 3.26843 261 | -0.65382, 2.06116 262 | 0.15328, 4.44468 263 | 0.27070, 4.70569 264 | 0.36162, 5.24407 265 | -0.84504, 1.35793 266 | -0.32438, 2.95835 267 | -0.03475, 3.79335 268 | 0.33396, 4.98564 269 | 0.16630, 4.44727 270 | -0.15143, 3.67755 271 | 0.30438, 5.10041 272 | 0.03120, 4.05984 273 | -0.77520, 1.88144 274 | -0.14037, 3.56899 275 | 0.29880, 4.83158 276 | -0.33808, 3.12041 277 | 0.45549, 5.46429 278 | 0.15316, 4.42278 279 | 0.36304, 5.06970 280 | 0.29205, 4.89947 281 | -0.21502, 3.31810 282 | 0.50244, 5.70052 283 | -0.50083, 2.51849 284 | -0.10209, 3.64899 285 | 0.71932, 6.24720 286 | -0.51712, 2.58274 287 | 0.32582, 5.13330 288 | 0.21761, 4.52737 289 | -0.31382, 3.09061 290 | 0.28443, 4.83296 291 | 0.32211, 4.85906 292 | 0.16218, 4.54017 293 | 0.24560, 4.69198 294 | 0.17659, 4.63960 295 | -0.68139, 1.98224 296 | 0.40254, 5.19793 297 | 0.32996, 5.15711 298 | 0.10857, 4.22875 299 | 0.34091, 5.04461 300 | -0.21996, 3.29980 301 | -------------------------------------------------------------------------------- /contoh/linear-regression.py: -------------------------------------------------------------------------------- 1 | #read CSV of data and calculate a and b 2 | # y = ax + b 3 | import numpy as np 4 | # do not forget to install scipy first: python3 -m pip install scipy 5 | from scipy import stats 6 | 7 | #my_csv = np.genfromtxt('linear-regression.csv', delimiter=',') 8 | my_csv = np.genfromtxt('linear-regression-pr.csv', delimiter=',') 9 | xp, yp = my_csv.transpose() 10 | gradient,intercept,r_value,p_value,std_err=stats.linregress(xp,yp) 11 | print("Gradient and intercept",gradient,intercept) 12 | print("R-squared",r_value**2) 13 | print("p-value",p_value) 14 | -------------------------------------------------------------------------------- /contoh/list.py: -------------------------------------------------------------------------------- 1 | # contoh list di Python 2 | daftar = [7, 1, 5, 3, 2, 4, 6, 8, 3, 5] 3 | print(daftar) 4 | print("list memiliki", len(daftar), "elemen") 5 | 6 | # akses elemen yang pertama (dengan indeks 0) 7 | print("daftar[0] =", daftar[0]) 8 | 9 | # menambahkan data ke list 10 | daftar = daftar + [7, 9] 11 | print(daftar) 12 | 13 | # mengurutkan 14 | urut = sorted(daftar) 15 | print("terurut:", urut) 16 | -------------------------------------------------------------------------------- /contoh/log-processing/parsing-access-log.py: -------------------------------------------------------------------------------- 1 | import apache_log_parser 2 | line_parser = apache_log_parser.make_parser("%a %l %u %t \"%r\" %>s %b") 3 | 4 | from pprint import pprint 5 | 6 | # baris = '103.90.64.250 - - [14/Apr/2018:06:25:08 +0700] "GET /weatherstation/updateweatherstation.php?ID=IBANDUNG8&tempf=69.80&humidity=59.00&softwaretype=BRIotv1&action=updateraw&realtime=1&rtfreq=5 HTTP/1.1" 502 172 "-" "-"' 7 | 8 | count=1 9 | 10 | import fileinput 11 | for baris in fileinput.input(): 12 | if "ID" in baris: 13 | hasil = line_parser(baris) 14 | #pprint(hasil) 15 | 16 | waktu = hasil['time_received_datetimeobj'] 17 | 18 | webdata = hasil['request_url_query_simple_dict'] 19 | #pprint(webdata) 20 | 21 | # kumpulkan hasil 22 | id = webdata['ID'] 23 | tempf = webdata['tempf'] 24 | humidity = webdata['humidity'] 25 | print(count, waktu, id, tempf, humidity) 26 | # print(count, end=', ') 27 | # print(waktu, end=', ') 28 | # print(id, end = ', ') 29 | # print(tempf, end = ', ') 30 | # print(humidity) 31 | count = count+1 32 | -------------------------------------------------------------------------------- /contoh/loop.py: -------------------------------------------------------------------------------- 1 | for i in range(10): 2 | print i 3 | -------------------------------------------------------------------------------- /contoh/negatif.py: -------------------------------------------------------------------------------- 1 | # contoh branching 2 | x = input("Masukkan bilangan antara -10 dan 10: "); 3 | z = int(x) 4 | if z < 0: 5 | print("Anda memasukkan bilangan negatif, ", z) 6 | else: 7 | print("Anda memasukkan bilangan positif, ", z) 8 | -------------------------------------------------------------------------------- /contoh/numpy-matrix.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | a = np.array([[1,2,3],[4,5,6],[7,8,9]]) 4 | print(a) 5 | b = np.array([[3,3,3],[5,5,5],[5,3,1]]) 6 | print(b) 7 | 8 | c = a+b 9 | print(c) 10 | 11 | d = np.matmul(a, b) 12 | print(d) 13 | -------------------------------------------------------------------------------- /contoh/opencv-grey.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | img = cv2.imread('../graphics/br-pixel.png') 4 | grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 5 | 6 | cv2.imshow('Gambar Asli', img) 7 | cv2.imshow('Gambar grey', grey) 8 | 9 | cv2.waitKey(0) 10 | cv2.destroyAllWindows() 11 | -------------------------------------------------------------------------------- /contoh/pandas-readcsv.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | df = pd.read_csv('cluster.csv', header=None) 4 | df.columns = ['x', 'y'] 5 | print(df) 6 | -------------------------------------------------------------------------------- /contoh/pandas-readplat.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | df = pd.read_csv('platnomor.csv') 4 | print(df) 5 | -------------------------------------------------------------------------------- /contoh/platnomor.csv: -------------------------------------------------------------------------------- 1 | Plate,Owner,Maker,Model 2 | D1234XYZ,Budi,Ferari,F1 3 | B1444AR,Dudung,Toyota,Corola 4 | D454R,Fulan,Tesla,Angkot 5 | D491NG,Joni,Tesla,Sport 6 | A1111NG,Cecep,Toyota,Avanza 7 | -------------------------------------------------------------------------------- /contoh/platnomor.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/contoh/platnomor.xlsx -------------------------------------------------------------------------------- /contoh/prosesteks.py: -------------------------------------------------------------------------------- 1 | 2 | # text processing 3 | # memecah kalimat menjadi kata-kata 4 | kalimat = raw_input("Masukkan kalimat yang cukup panjang.\n") 5 | # pisahkan menjadi kata 6 | kata = kalimat.split() 7 | for k in kata: 8 | print k 9 | -------------------------------------------------------------------------------- /contoh/readcsv.py: -------------------------------------------------------------------------------- 1 | f = open('data.txt', 'r') 2 | 3 | x = [] 4 | y = [] 5 | while True: 6 | line = f. readline() 7 | if not line: 8 | break 9 | line = line.rstrip() 10 | a,b = line.split(',') 11 | x.append(int(a)) 12 | y.append(int(b)) 13 | 14 | print x,y 15 | -------------------------------------------------------------------------------- /contoh/tf-grad-decent.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | a = 0.25 5 | b = 0.75 6 | jumlah_titik = 300 7 | 8 | # buat dua list yang masih kosong 9 | x_point = [] 10 | y_point = [] 11 | 12 | for i in range(jumlah_titik): 13 | x = np.random.normal(0.0,0.4) 14 | y = a*x + b + np.random.normal(0.0,0.1) 15 | x_point.append([x]) 16 | y_point.append([y]) 17 | 18 | plt.plot(x_point,y_point,'o',label='Random Data') 19 | plt.legend() 20 | plt.show() 21 | -------------------------------------------------------------------------------- /graphics/3cluster-kmeans.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/graphics/3cluster-kmeans.jpg -------------------------------------------------------------------------------- /graphics/3cluster.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/graphics/3cluster.jpg -------------------------------------------------------------------------------- /graphics/br-pixel-grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/graphics/br-pixel-grey.png -------------------------------------------------------------------------------- /graphics/br-pixel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/graphics/br-pixel.png -------------------------------------------------------------------------------- /graphics/cluster-create.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/graphics/cluster-create.jpg -------------------------------------------------------------------------------- /graphics/google-colab.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/graphics/google-colab.jpg -------------------------------------------------------------------------------- /graphics/kecil.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/graphics/kecil.jpg -------------------------------------------------------------------------------- /graphics/matplotlib-contoh1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/graphics/matplotlib-contoh1.png -------------------------------------------------------------------------------- /graphics/matplotlib-contoh2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/graphics/matplotlib-contoh2.png -------------------------------------------------------------------------------- /graphics/matplotlib-gausian.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/graphics/matplotlib-gausian.png -------------------------------------------------------------------------------- /graphics/random-data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/graphics/random-data.png -------------------------------------------------------------------------------- /opencv.tex: -------------------------------------------------------------------------------- 1 | \section{OpenCV} 2 | OpenCV adalah kumpulan pustaka untuk bidang {\em computer vision} 3 | atau {\em image processing}. 4 | Pustaka ini dapat diakses dengan menggunakan bermacam-macam bahasa pemrograman, 5 | termasuk bahasa Python. 6 | Untuk memasang pustaka atau modul ini gunakan perintah. 7 | 8 | \begin{verbatim} 9 | pip install opencv-python 10 | \end{verbatim} 11 | 12 | Berikut ini adalah sebuah contoh penggunaan OpenCV untuk membaca 13 | sebuah berkas gambar dan mengubahnya warnanya menjadi abu-abu (greyscale). 14 | Perhatikan nama berkas yang dalam contoh ini berada di direktori 15 | satu tingkat di atasnya. Ganti nama berkas ini dengan nama yang sesuai 16 | dengan berkas yang ingin Anda proses. 17 | 18 | \begin{verbatim} 19 | import cv2 20 | img = cv2.imread('../graphics/br-pixel.png') 21 | grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 22 | cv2.imshow('Gambar Asli', img) 23 | cv2.imshow('Gambar grey', grey) 24 | cv2.waitKey(0) 25 | cv2.destroyAllWindows() 26 | \end{verbatim} 27 | 28 | Program akan menampilkan gambar sebelum dan sesudah diproses, 29 | kemudian menunggu sampai kita menekan sesuatu di keyboard sebelum 30 | akhirnya menutup semua peragaan gambar tersebut. 31 | Hasil pemrosesan kode di atas dapat dilihat pada gambar-gambar 32 | berikut. 33 | 34 | \begin{figure} 35 | \includegraphics[width=1.0\linewidth]{graphics/br-pixel.png} 36 | \caption{Gambar asli} 37 | \end{figure} 38 | 39 | \begin{figure} 40 | \includegraphics[width=1.0\linewidth]{graphics/br-pixel-grey.png} 41 | \caption{Hasil proses} 42 | \end{figure} 43 | 44 | Perhatikan betapa mudahnya menggunakan OpenCV untuk melakukan proses tersebut. 45 | Konversi warna itu dapat kita lakukan dengan satu perintah saja. 46 | Tanpa pustaka ini kita harus membuat sebuah {\em loop} yang mengubah 47 | setiap piksel dari gambar tersebut. 48 | 49 | Modul OpenCV ini dapat digunakan di berbagai aplikasi, termasuk untuk 50 | Artificial Intelligence atau Machine Learning. 51 | -------------------------------------------------------------------------------- /optparams.sty: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `optparams.sty', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% optparams.dtx (with options: `package') 8 | %% 9 | \NeedsTeXFormat{LaTeX2e} 10 | \ProvidesPackage{optparams} 11 | [2004/08/14 v0.9 multiple optional parameters in macros] 12 | \newcommand{\optparams}[2]{% 13 | \optparams@{#1}{}{#2}% 14 | } 15 | \def\optparams@#1#2#3{% 16 | \@ifnextchar[{% 17 | \optparams@@{#1}{#2}#3\@nil% 18 | }{% 19 | #1#2#3% 20 | }% 21 | } 22 | \def\optparams@@#1#2[#3]#4\@nil[#5]{% 23 | \optparams@{#1}{#2[#5]}{#4}% 24 | } 25 | \endinput 26 | %% 27 | %% End of file `optparams.sty'. 28 | -------------------------------------------------------------------------------- /pendahuluan.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\zref@newlabel[2]{} 4 | \@writefile{toc}{\contentsline {chapter}{\numberline {1}Pendahuluan}{7}{chapter.1}\protected@file@percent } 5 | \@writefile{lof}{\addvspace {10\p@ }} 6 | \@writefile{lot}{\addvspace {10\p@ }} 7 | \@writefile{toc}{\contentsline {section}{\numberline {1.1}Instalasi}{8}{section.1.1}\protected@file@percent } 8 | \@writefile{toc}{\contentsline {section}{\numberline {1.2}Python Tanpa Instalasi - Google Colab}{8}{section.1.2}\protected@file@percent } 9 | \newpmemlabel{^_1}{8} 10 | \@writefile{lof}{\contentsline {figure}{\numberline {1.1}{\ignorespaces Tampilan Google Colab}}{9}{section.1.2}\protected@file@percent } 11 | \@writefile{toc}{\contentsline {section}{\numberline {1.3}Memulai}{9}{section.1.3}\protected@file@percent } 12 | \@writefile{toc}{\contentsline {section}{\numberline {1.4}Shell atau IDE}{11}{section.1.4}\protected@file@percent } 13 | \@writefile{toc}{\contentsline {section}{\numberline {1.5}Bahasa Python}{12}{section.1.5}\protected@file@percent } 14 | \@writefile{toc}{\contentsline {section}{\numberline {1.6}Kompleksitas}{14}{section.1.6}\protected@file@percent } 15 | \@writefile{toc}{\contentsline {section}{\numberline {1.7}List}{16}{section.1.7}\protected@file@percent } 16 | \@writefile{toc}{\contentsline {section}{\numberline {1.8}Input}{18}{section.1.8}\protected@file@percent } 17 | \@writefile{toc}{\contentsline {section}{\numberline {1.9}Pencabangan - Branching}{20}{section.1.9}\protected@file@percent } 18 | \@writefile{toc}{\contentsline {section}{\numberline {1.10}Pemrosesan Teks}{20}{section.1.10}\protected@file@percent } 19 | \@writefile{toc}{\contentsline {section}{\numberline {1.11}Membaca Berkas: topic generator}{21}{section.1.11}\protected@file@percent } 20 | \@writefile{toc}{\contentsline {section}{\numberline {1.12}Python3}{23}{section.1.12}\protected@file@percent } 21 | \@setckpt{pendahuluan}{ 22 | \setcounter{page}{24} 23 | \setcounter{equation}{0} 24 | \setcounter{enumi}{0} 25 | \setcounter{enumii}{0} 26 | \setcounter{enumiii}{0} 27 | \setcounter{enumiv}{0} 28 | \setcounter{footnote}{3} 29 | \setcounter{mpfootnote}{0} 30 | \setcounter{part}{0} 31 | \setcounter{chapter}{1} 32 | \setcounter{section}{12} 33 | \setcounter{subsection}{0} 34 | \setcounter{subsubsection}{0} 35 | \setcounter{paragraph}{0} 36 | \setcounter{subparagraph}{0} 37 | \setcounter{figure}{1} 38 | \setcounter{table}{0} 39 | \setcounter{Item}{0} 40 | \setcounter{bookmark@seq@number}{13} 41 | \setcounter{cp@cntr}{1} 42 | \setcounter{NAT@ctr}{0} 43 | \setcounter{@tufte@num@bibkeys}{0} 44 | \setcounter{Exercise}{0} 45 | \setcounter{Answer}{0} 46 | \setcounter{ExePart}{0} 47 | \setcounter{Question}{0} 48 | \setcounter{subQuestion}{0} 49 | \setcounter{subsubQuestion}{0} 50 | \setcounter{savedQuestion}{0} 51 | \setcounter{savedsubQuestion}{0} 52 | \setcounter{savedsubsubQuestion}{0} 53 | \setcounter{mdf@globalstyle@cnt}{0} 54 | \setcounter{mdfcountframes}{0} 55 | \setcounter{mdf@env@i}{0} 56 | \setcounter{mdf@env@ii}{0} 57 | \setcounter{mdf@zref@counter}{0} 58 | \setcounter{parentequation}{0} 59 | \setcounter{@pps}{0} 60 | \setcounter{@ppsavesec}{0} 61 | \setcounter{@ppsaveapp}{0} 62 | \setcounter{section@level}{0} 63 | } 64 | -------------------------------------------------------------------------------- /pendahuluan.tex: -------------------------------------------------------------------------------- 1 | \chapter{Pendahuluan} 2 | Bahasa pemrograman Python mulai populer saat dikarenakan berbagai hal; mudah 3 | dipelajari, tersedia dan banyak {\em library}-nya. Nanti akan kita bahas beberapa 4 | library Python ini. Lengkapnya library ini juga yang menyebabkan 5 | Python dipergunakan di berbagai aplikasi. Berbagai sekolah (dan 6 | perguruan tinggi) bahkan mengajarkan Python sebagai pengantar pemrograman. 7 | 8 | Bahasa Python dianggap agak ``mudah'' digunakan sehingga dapat diajarkan 9 | kepada orang-orang yang tidak memiliki latar belakang pendidikan pemrograman. 10 | Jadi Python digunakan oleh orang-orang di bidang Biologi sampai Bahasa. 11 | Manager-manager yang ingin belajar statistik atau {\em data science} 12 | dapat menggunakan bahasa Python ini. 13 | Alternatifnya adalah belajar menggunakan bahasa R, tetapi kalau 14 | nanti ingin melakukan pemrograman untuk yang lainnya lagi harus belajar 15 | bahasa pemrograman lagi. Daripada seperti itu, lebih baik belajar satu 16 | bahasa saja. Pilihannya adalah bahasa Python. 17 | 18 | Bahasa Python merupakan sebuah {\em interpreted language} berbeda dengan 19 | bahasa C yang {\em compiled}. Pada bahasa yang {\em compiled}, kita memiliki 20 | kode sumber ({\em source code}) yang harus dirakit ({\em compile}) dahulu 21 | sampai menjadi kode mesin yang langsung dapat dieksekusi pada komputer 22 | yang bersangkutan. Ketika algoritma salah, maka kode sumber harus diperbaiki 23 | dahulu kemudian di-{\em compile}) sebelum dapat dijalankan. Prosesnya 24 | menjadi agak panjang. Sementara itu untuk bahasa yang {\em interpreted}, 25 | program langsung dieksekusi dari kode sumbernya (tanpa perlu proses kompilasi). 26 | Dahulu program yang {\em compiled} lebih cepat dalam eksekusinya karena 27 | tidak perlu menerjemahkan baris perbaris ketika dijalankan, namun sekarang 28 | perbedaannya sudah tipis. 29 | 30 | Bahasa Python tersedia untuk berbagai sistem operasi; Windows, Mac OS, dan 31 | berbagai variasi dari UNIX (Linux, *BSD, dan seterusnya). Di dalam buku ini 32 | saya akan menggunakan contoh-contoh yang saya gunakan di komputer saya yang 33 | berbasis Linux Mint. Meskipun seharusnya semuanya kompatibel dengan berbagai 34 | sistem operasi, kemungkinan ada hal-hal yang agak berbeda. Jika hal itu 35 | terjadi, gunakan internet untuk mencari jawabannya. 36 | 37 | \section{Instalasi} 38 | Python dapat diperoleh secara gratis dari berbagai sumber. Sumber utamanya 39 | adalah di situs python.org. Untuk sementara ini bagian ini saya serahkan kepada 40 | Anda. Ada terlalu banyak perubahan sehingga bagian ini akan cepat kadaluwarsa. 41 | Untuk sistem berbasis sistem operasi Microsoft Windows, biasanya instalasi 42 | Python menggungankan {\em Anaconda}. (Informasi mengenai ini juga dapat 43 | dilihat pada situs python.org.) 44 | 45 | Untuk sistem operasi berbasis Linux dan Mac OS, Python sudah terpasang sebagai 46 | bawaan dari sistem operasinya. Jika Anda ingin memasang versi terbaru maka 47 | Anda harus memasangnya sendiri dengan mengunduh instalasinya di python.org. 48 | Atau, jika Python sudah terpasang di komputer Anda, maka Anda dapat melakukan 49 | {\em upgrade}. 50 | 51 | \section{Python Tanpa Instalasi - Google Colab} 52 | 53 | Ada cara lain menggunakan Python adalah dengan menggunakan layanan 54 | {\bf Google Colabs}, yang mana kita diberikan akses ke sebuah mesin virtual 55 | yang sudah terpasang Python. Python berada di {\em cloud}. 56 | Untuk pendekatan ini kita tidak perlu memasang Python lagi. 57 | Lebih mudah untuk belajar dan bahkan untuk membuat prototipe. 58 | 59 | Bagi saya, sebagai seorang dosen, pemanfaatan Google Colab ini 60 | sangat menarik karena siswa akan memiliki konfigurasi yang sama. 61 | Seringkali kalau mengajar di kelas dengan komputer yang berbeda-beda 62 | (beda sistem operasi, beda versi Python, letak instalasi, beda versi 63 | dari {\em library}, dan seterusnya), waktu dan tenaga akan habis untuk 64 | mengurusi hal-hal yang tidak jalan karena perbedaan tersebut. 65 | Bagi Anda yang mengajar Python, saya sarankan untuk menggunakan 66 | pendekatan dengan menggunakan Google Colab ini. 67 | 68 | Buku ini akan diperbaharui dengan cara menggunakan Google Colabs ini. 69 | 70 | \begin{figure} 71 | \includegraphics[width=1.0\linewidth]{graphics/google-colab.jpg} 72 | \caption{Tampilan Google Colab} 73 | \end{figure} 74 | 75 | Layanan Google Colab dapat diakses dengan menggunakan {\em browser} dan 76 | diarahkan ke alamat colab.research.google.com (atau gunakan search engine 77 | untuk mencapai halaman tersebut dengan kata kunci "google colab"). 78 | Setelah ditampilkan halaman depan, kita dapat membuka program baru dengan 79 | membuka {\em New Notebook} atau membukan kodingan lama kita yang sudah 80 | disimpan di akun Google Drive kita. 81 | Google colab menyediakan sebuah komputer virtual yang dapat kita gunakan 82 | untuk melakukan pemrograman dalam bahasa Python . 83 | 84 | \section{Memulai} 85 | Untuk memastikan Python berjalan, ketikkan ``python'' di terminal Linux Anda. 86 | (Bagi yang menggunakan Windows, hal ini dapat dilakukan dengan menggunakan 87 | CMD.exe.) Catatan, di sistem Linux, tanda ``dollar'' (atau persen) 88 | merupakan {\em prompt} dari {\em shell} Anda. Jangan diketikkan. 89 | Di beberapa sistem yang memiliki instalasi Python~2 dan Pyhton~3 secara 90 | bersamaan, ada kemungkinan Anda harus mengetikkan ``python3'' 91 | (perhatikan ada angka ``3''). 92 | Di kemudian hari, {\em default} dari perintah `python' akan mengacu 93 | kepada versi 3. 94 | 95 | \begin{verbatim} 96 | % python3 97 | Python 3.9.10 (main, Jan 15 2022, 11:40:53) 98 | [Clang 13.0.0 (clang-1300.0.29.3)] on darwin 99 | Type "help", "copyright", "credits" or "license" for more information. 100 | >>> 101 | \end{verbatim} 102 | 103 | Sekarang kita dapat memulai pemrograman Python dengan menuliskan 104 | program ``hello world'' (yang merupakan standar bagi belajar pemrograman). 105 | Ketikkan ``print ...'' (dan seterusnya seperti di bawah ini). 106 | 107 | \begin{verbatim} 108 | print("Hello, world!") 109 | \end{verbatim} 110 | 111 | Python akan menampilkan apapun yang ada di antara tanda petik tersebut. Hore! 112 | Selamat! Anda berhasil membuat program Python yang pertama. 113 | 114 | Ada beberapa cara untuk menjalankan Python. Pada contoh di atas, kita 115 | menjalankannya secara langsung. Cara ini memang yang paling cepat, tetapi ada 116 | banyak hal yang harus kita lakukan secara manual. Sebagai contoh, jika kita 117 | ingin membuat sebuah {\em block}, maka kita harus mengetikkan sendiri empat 118 | spasi untuk membuatnya masuk. Jika ini tidak kita lakukan, maka dia akan 119 | ``marah'' dan menampilkan pesan. Berikut ini contoh sesi yang salah. 120 | 121 | \begin{verbatim} 122 | $ python3 123 | Python 3.5.2 (default, Nov 23 2017, 16:37:01) 124 | [GCC 5.4.0 20160609] on linux 125 | Type "help", "copyright", "credits" or "license" for more information. 126 | >>> for i in range(10): 127 | ... print(i) 128 | File "", line 2 129 | print(i) 130 | ^ 131 | IndentationError: expected an indented block 132 | >>> 133 | \end{verbatim} 134 | 135 | Pada contoh di atas, kesalahan terjadi karena kita tidak memberikan spasi di 136 | depan perintah ``print(i)''. Seharusnya kita melakukan hal seperti ini. 137 | (Perhatikan spasi sebelum kata ``print''.) 138 | Sayangnya dengan cara di atas kita akan sulit mengedit ulang. 139 | Lebih disarankan untuk menggunakan text editor atau IDE untuk membuat 140 | program Python secara lebih serius. 141 | 142 | \begin{verbatim} 143 | $ python3 144 | Python 3.5.2 (default, Nov 23 2017, 16:37:01) 145 | [GCC 5.4.0 20160609] on linux 146 | Type "help", "copyright", "credits" or "license" for more information. 147 | >>> for i in range(10): 148 | ... print(i) 149 | ... 150 | 0 151 | 1 152 | 2 153 | 3 154 | 4 155 | 5 156 | 6 157 | 7 158 | 8 159 | 9 160 | >>> 161 | \end{verbatim} 162 | 163 | 164 | Mari kita lanjutkan dengan membuat program yang lebih panjang. Program Python 165 | dapat disimpan di dalam sebuah berkas untuk kemudian dieksekusi belakangan. 166 | Buka editor kesukaan Anda dan ketikkan program hello world di atas di dalam 167 | editor Anda tersebut. Setelah itu simpan berkas tersebut dengan nama 168 | ``hello.py''. Biasanya berkas program Python ditandai dengan akhiran 169 | (extension) ``.py''. 170 | 171 | Setelah berkas tersebut tersedia, maka kita dapat menjalankan Python dengan 172 | memberikan perintah python dan nama berkas tersebut. 173 | Kata ``Hello world'' akan ditampilkan. 174 | 175 | \begin{verbatim} 176 | $ python3 hello.py 177 | Hello, world! 178 | \end{verbatim} 179 | 180 | Kode kedua yang akan kita buat adalah membuat Python mencetak angka dari 181 | nol (0) ke 9. Kodenya adalah sebagai berikut. 182 | 183 | 184 | \begin{verbatim} 185 | for n in range(10): 186 | print(n) 187 | \end{verbatim} 188 | 189 | Setelah kode ini disimpan 190 | dalam sebuah berkas (katakan kita beri nama ``loop.py'') maka kita jalankan 191 | dengan perintah ``python3 loop.py'' 192 | 193 | \begin{verbatim} 194 | $ python3 loop.py 195 | 0 196 | 1 197 | 2 198 | 3 199 | 4 200 | 5 201 | 6 202 | 7 203 | 8 204 | 9 205 | \end{verbatim} 206 | 207 | Pada contoh-contoh di atas hasil print dicetak ke bawah. Bagaimana jika kita 208 | ingin hasil cetaknya tidak turun ke bawah atau tanpa {\em newline}? 209 | Cara berikut ini - dengan menambahkan (end = " ") - dapat digunakan: 210 | 211 | \begin{verbatim} 212 | for n in range(10): 213 | print(n, end=" ") 214 | \end{verbatim} 215 | Keluaran dari program di atas adalah cetakan yang ke kanan. 216 | \begin{verbatim} 217 | 0 1 2 3 4 5 6 7 8 9 218 | \end{verbatim} 219 | 220 | 221 | \section{Shell atau IDE} 222 | Pemrograman Python dapat dilakukan dengan editor seperti yang sudah ditunjukkan 223 | di atas dan kemudian menjalankannya secara {\em command line} di shell, 224 | Cara lain yang lebih sering dilakukan orang adalah menggunakan sebuah 225 | Integrated Development Editor (IDE) untuk melakukan pemrogramannnya. 226 | Menjalankan kodenya dapat dikomandokan dari IDE atau dari shell juga. 227 | 228 | Ada beberapa IDE untuk Python, seperti misalnya IDLE atau dengan 229 | {\em Jupyter Notebook}. 230 | Yang menarik dengan pendekatan ini adalah kita melakukan dokumentasi dan 231 | pemrograman sekaligus di lingkungan tersebut. 232 | Google Colab pun sesungguhnya menggunakan konsep Jupyter Notebook ini tetapi 233 | membawanya ke lingkungan {\em cloud}. 234 | Nanti ini akan kita bahas dengan lebih lanjut. 235 | 236 | Bagi Anda yang sudah terbiasa menggunakan Visual Code Studio (VScode), 237 | Anda dapat juga menggunakannya sebagai IDE untuk mengetikkan kode Python Anda. 238 | Bahkan cara ini sekarang yang sedang populer. 239 | Di dalam VSCode ada juga syntax highlighting yang menunjukkan kesalahan 240 | jika kode kita tidak sesuai dengan keyword Python. 241 | 242 | \section{Bahasa Python} 243 | Tentang bahasa Python itu sendiri akan diperdalam pada versi berikutnya. 244 | Sementara itu fitur tentang bahasa Python akan dibahas sambil berjalan. 245 | Pendekatan ini saya ambil untuk membuat buku menjadi lebih menarik dan lebih 246 | singkat. Belajar seperlunya. Mari kita mulai. 247 | 248 | Kita mulai dengan konsep variabel. Sebagai mana bahasa pemrograman lainnya, 249 | Python juga memiliki konsep variabel untuk menampung data. 250 | 251 | Variabel di dalam Python langsung dapat digunakan tanpa melakukan deklarasi 252 | sebelumnya. Pada bahasa pemrograman seperti C, variabel harus dideklarasikan 253 | tipenya; apakah dia {\em integer} atau {\em string} atau tipe data lainnya. 254 | Pada Python, tidak perlu. Dia akan menebak tipe datanya. 255 | (Namun jika kita merasa perlu mendeklarasikannya, ini dapat dilakukan juga.) 256 | Contohnya di bawah ini. 257 | \begin{verbatim} 258 | a = 7 259 | b = 5 260 | print(a,b) 261 | \end{verbatim} 262 | Pada contoh di atas, variabel $a$ dan $b$ dibuat dan langsung diisi dengan 263 | angka (7 dan 5), bilangan bulat (integer) dalam kasus ini. 264 | Kemudian kedua variabel tersebut disampaikan sekaligus. 265 | Perhatikan bahwa dengan menggunakan tanda koma (,) nilai dari kedua variabel 266 | tersebut ditampilkan dengan spasi. 267 | 268 | \begin{verbatim} 269 | 7 5 270 | \end{verbatim} 271 | 272 | Berikut ini kita buat penampilan yang lebih ``menarik'' (karena ada teks yang 273 | menjelaskan apa yang dia tampilkan di layar). 274 | \begin{verbatim} 275 | a = 7 276 | b = 5 277 | c = a + b 278 | print ("a = ", a) 279 | print ("b = ", b) 280 | print ("a+b = ", c) 281 | \end{verbatim} 282 | 283 | Keluaran dari Python3 adalah seperti ini: 284 | \begin{verbatim} 285 | a = 7 286 | b = 5 287 | a+b = 12 288 | \end{verbatim} 289 | 290 | Hal yang sangat berbeda dari bahasa Python dengan 291 | bahasa pemrograman lainnya adalah masalah {\em block} dari kode. 292 | Bahasa pemrograman C misalnya menggunakan tanda kurung kurawal ``\{'' 293 | untuk menyatakan blok. Sementara itu Python menggunakan {\em indentation} 294 | untuk menyatakan satu blok. Lihat contoh di bawah ini. 295 | 296 | \begin{verbatim} 297 | for i in range(5): 298 | for j in range(3): 299 | print(i,j) 300 | \end{verbatim} 301 | 302 | Disarankan untuk menggunakan spasi sebanyak empat (4) buah untuk {\em 303 | indentation} tersebut. (Ini membuat banyak perdebatan karena ada banyak orang 304 | yang menggunakan tab bukan spasi.) 305 | 306 | Mari kita buat contoh-contoh lain. Apa keluaran program di bawah ini? 307 | \begin{verbatim} 308 | nama1 = "budi" 309 | nama2 = "rahardjo" 310 | nama3 = nama1 + nama2 311 | print(nama3) 312 | \end{verbatim} 313 | 314 | Perhatikan bahwa untuk variabel yang berjenis angka (integer) maka operator 315 | tambah (+) akan menambahkan angkanya. Sementara itu pada variabel yang 316 | berjenis {\em string}, operator (+) akan menyambungkan ({\em concatenate}) 317 | variabel {\em string} tersebut. 318 | Ini merupakan ciri dari sebuah bahasa yang berorientasi obyek 319 | ({\em object oriented}). 320 | Untuk tipe data yang lainnya, operator tambah (+) kemungkinan juga akan 321 | memiliki perilaku yang berbeda. 322 | 323 | Mari kembali ke data yang berbentuk angka. Apa keluaran dari program 324 | di bawah ini? 325 | \begin{verbatim} 326 | a = 7 327 | b = 5 328 | c = a/b 329 | print(c) 330 | \end{verbatim} 331 | 332 | Keluarannya adalah nilai ``1.4''. Jenis atau tipe data dari ``a'' dan ``c'' 333 | adalah berbeda. Tipe data ``a'' adalah {\em integer}, sementara itu 334 | tipe data ``c'' adalah {\em floating point}. 335 | 336 | \begin{verbatim} 337 | >>> a=7 338 | >>> type(a) 339 | 340 | >>> b=5 341 | >>> c=a/b 342 | >>> type(c) 343 | 344 | \end{verbatim} 345 | 346 | Bolehkah kita mencampurkan tipe data yang berbeda? 347 | Mari kita lanjutkan dengan contoh di atas. 348 | \begin{verbatim} 349 | d = a+c 350 | print(d) 351 | \end{verbatim} 352 | Keluaran dari kode di atas adalah ``8.4''. Artinya pencampuran tipe data 353 | yang berbeda (dalam hal ini adalah {\em integer} dan {\em float}) dapat 354 | dilakukan. Hasilnya adalah bilangan {\em float}. 355 | Hal ini menunjukkan bahwa bahasa Python dapat dibuat tidak {\em strict}. 356 | Bahasa pemrograman lain - misalnya Java (dan umumnya bahasa pemrograman 357 | yang berorientasi obyek) - sangat ketat dalam hal ini. 358 | 359 | 360 | \section{Kompleksitas} 361 | Pada bagian sebelumnya kebetulan sempat disinggung tentang {\em loop}, 362 | maka pada bagian ini pembahasannya sedikit melebar ke aspek Kompleksitas 363 | (dari subuah algoritme). 364 | Ini memang lebih berbau aspek teoritis dari ilmu komputer. 365 | 366 | Ketika seseorang mengembangkan atau menggunakan sebuah algoritme untuk 367 | mengimplementasikan programnya, maka ada satu hal yang perlu diperhatikan 368 | yaitu kompleksitas. 369 | Singkatnya, kompleksitas itu menunjukkan seberapa besar sumber daya yang 370 | akan digunakan (dibutuhkan) untuk menjalankan algoritme tersebut sebagai 371 | sebuah fungsi dari jumlah data yang diproses. 372 | Sebagai contoh, sebuah aplikasi mungkin berjalan dengan baik ketika jumlah 373 | datanya hanya 100, tetapi kemudian menjadi sangat lambat atau bahkan tidak 374 | jalan ketika jumlah datanya 1000 atau lebih. 375 | Nah jumlah data tersebut (100 atau 1000) merupakan sebuah paramter yang 376 | menjadi fungsi dari sumber daya yang digunakan. Biasanya ini kita sebut $n$. 377 | Kompleksitas kemudian menjukkan seberapa besar sumber daya sebagai fungsi 378 | dari $n$ itu. 379 | 380 | Ada algoritme yang lama komputasinya bergantung liner terhadap jumlah data 381 | ($n$) itu. Jadi misalnya untuk 100 data dibutuhkan 100 detik, maka untuk 382 | 1000 data dibutuhkan waktu 1000 detik. Bagaimana jika jumlah datanya 10000? 383 | Maka dapat diperkirakan waktu yang dibutuhkan adalah 10000 detik. 384 | Kompleksitas yang sepert ini disebuh $O(n)$. 385 | 386 | Ada juga algoritme yang lama perhitungannya berbanding kuadratis (pangkat dua) 387 | terhadap jumlah datanya. 388 | Kompleksitas yang model seperti ini disebut $O(n^{2})$ 389 | 390 | 391 | \begin{verbatim} 392 | n=1000 393 | import time 394 | 395 | start_time = time.time() 396 | a = 0 397 | for x in range(n): 398 | a = a + 0 399 | end_time = time.time() 400 | elapsed = end_time - start_time 401 | print("elapsed %s seconds ..." % elapsed) 402 | \end{verbatim} 403 | 404 | Contoh kode di atas menunjukkan sebuah {\em loop} dengan 1000 kali putaran. 405 | Jumlah loop ditentukan oleh variabel $n$, yang pada contoh di atas diisi 1000. 406 | Di dalam setiap loop ada perintah {\em dummy}, yaitu variabel $a$ ditambah 407 | dengan bilangan nol. Ini hanya sekedar untuk menunjukkan beban komputasi penjumlahan. 408 | Tentu saja di dalam dunia nyata, komputasiny lebih berat. 409 | 410 | Jika program tersebut dijalankan maka dia akan menghasilkan waktu eksekusi 411 | sebanyak $4,5538 \times 10^{-5}$ detik. 412 | Angka tepatnya tentu saja bergantung kepada komputer yang digunakan. 413 | Ini hanya sebagai contoh saja, yang kebetulan diambil dari laptop saya. 414 | 415 | Sekarang mari kita tambahkan loop di dalamnya sehingga kodenya menjadi seperti berikut. 416 | 417 | \begin{verbatim} 418 | n=1000 419 | import time 420 | 421 | start_time = time.time() 422 | a = 0 423 | for x in range(n): 424 | for y in range(n): 425 | a = a + 0 426 | end_time = time.time() 427 | elapsed = end_time - start_time 428 | print("elapsed %s seconds ..." % elapsed) 429 | \end{verbatim} 430 | 431 | Pada prinsipnya, kita menambahkan sebuah loop lagi di dalam loop sebelumnya. 432 | Jadi di dalam loop yang $x$, kita menambahkan loop $y$ yang jumlah loop-nya 433 | juga sama ($n$). Jika kode ini dijalankan maka dihasilkan keluaran waktu 434 | $0,05148$ detik, atau $5,418 \times 10^{-2}$. 435 | Perhatikan bahwa waktu yang dibutuhkan untuk mengeksekusi ini 1000 kali 436 | lebih besar (lebih lambat) dari waktu sebelumnya. 437 | Kompleksitas dari algoritme ini menjadi $O(n^2)$. 438 | 439 | Mari kita tambahkan satu loop lagi di dalam loop $y$ sehingga kodenya menjadi 440 | seperti berikut. 441 | 442 | \begin{verbatim} 443 | n=1000 444 | import time 445 | 446 | start_time = time.time() 447 | a = 0 448 | for x in range(n): 449 | for y in range(n): 450 | for z in range(n): 451 | a = a + 0 452 | end_time = time.time() 453 | elapsed = end_time - start_time 454 | print("elapsed %s seconds ..." % elapsed) 455 | \end{verbatim} 456 | 457 | Seperti sebelumnya, kode ini kita jalankan juga. Hasilnya adalah $51,1767$ detik. 458 | Atau $5,11767 \times 10$. Perhatikan bahwa ini 1000 kali lebih lambat dari sebelumnya 459 | dan 1 juta kali lebih lambat dari loop yang pertama kali (yang hanya ada $x$). 460 | Kompleksitas dari algoritme ini adalah $O(n^3)$. 461 | 462 | Anda boleh mencoba menggantikan angka variabel $n$ tadi dengan 10000. 463 | Namun perlu diingat bahwa waktu yang dibutuhkan untuk menjalankan kode 464 | tersebut menjadi sangat lama. Jika Anda tertarik, coba jalankan. 465 | Berapa detik waktu yang dibutuhkan untuk menjalankan itu? 466 | 467 | Apa yang kita bahas ini adalah kompleksitas yang dikaitkan dengan lamanya 468 | (waktu) eksekusi. Ada juga kompleksitas yang terkait dengan besarnya 469 | memori yang dibutuhkan (untuk memproses data). 470 | Ini merupakan bahasan yang lebih kompleks, tetapi prinsipnya sama. 471 | 472 | \section{List} 473 | Python memiliki struktur data {\em list}, yang sama dengan {\em array} 474 | (larik) di bahasa pemrograman lainnya. Untuk membuat {\em list} kita 475 | menggunakan tanda siku kotak. Contoh berikut ini menunjukkan penggunaan 476 | struktur data {\em list}. 477 | 478 | \begin{verbatim} 479 | # contoh list di Python 480 | daftar = [7, 1, 5, 3, 2, 4, 6, 8, 3, 5] 481 | print(daftar) 482 | print("list memiliki", len(daftar), "elemen") 483 | 484 | # akses elemen yang pertama (dengan indeks 0) 485 | print("daftar[0] =", daftar[0]) 486 | 487 | # akses ke elemen terakhir 488 | print("terakhir =", daftar[-1]) 489 | 490 | # menambahkan data ke list 491 | daftar = daftar + [7, 9] 492 | print(daftar) 493 | \end{verbatim} 494 | 495 | Keluaran dari kode di atas adalah sebagai berikut. 496 | Perhatikan baris terakhir adalah karena penambahan dua elemen baru 497 | di list. 498 | \begin{verbatim} 499 | [7, 1, 5, 3, 2, 4, 6, 8, 3, 5] 500 | list memiliki 10 elemen 501 | daftar[0] = 7 502 | [7, 1, 5, 3, 2, 4, 6, 8, 3, 5, 7, 9] 503 | \end{verbatim} 504 | 505 | Ada banyak hal yang dapat kita lakukan dengan menggunakan struktur data 506 | {\em list} ini. Kita dapat menghapus ({\em delete},{\em remove}) 507 | elemen di daftar tersebut. 508 | Kita juga dapat memotong ({\em cut}) elemen yang berada di tengah-tengah. 509 | Selain itu juga kita dapat menghitung berapa kemunculan sebuah nilai 510 | tertentu pada {\em list} tersebut. 511 | 512 | \begin{verbatim} 513 | del daftar[3] 514 | print(daftar) 515 | [7, 1, 5, 2, 4, 6, 8, 3, 5, 7, 9] 516 | \end{verbatim} 517 | 518 | Untuk menghapus elemen terakhir kita juga dapat menggunakan cara lain, 519 | yaitu dengan menggunakan perintah pop. 520 | 521 | \begin{verbatim} 522 | daftar.pop() 523 | print(daftar) 524 | [7, 1, 5, 2, 4, 6, 8, 3, 5, 7] 525 | \end{verbatim} 526 | 527 | Untuk mengurutkan list dapat digunakan perintah {\tt sorted}. 528 | Jika kita ingin menggantikannya (in place), maka dapat kita gunakan 529 | perintah {\tt list.sort()}. (Catatan, dengan menggunakan perintah yang 530 | terakhir tersebut, isi variable yang lama akan tergantikan dengan 531 | yang sudah terurut.) 532 | \begin{verbatim} 533 | urut = sorted(daftar) 534 | print(urut) 535 | \end{verbatim} 536 | 537 | List juga dapat digunakan untuk tipe data lain, bukan hanya angka. 538 | Sebagai contoh, kita dapat membuat list dari kata (yang menggunakan 539 | tipe data {\em string}.) Perhatikan bahwa kita dapat menggunakan 540 | huruf kecil dan besar. 541 | 542 | \begin{verbatim} 543 | people = ["budi", "cecep", "rudi", "ani", "BUDI", "rahardjo", "zoro"] 544 | print(people) 545 | 546 | ['budi', 'cecep', 'rudi', 'ani', 'BUDI', 'rahardjo', 'zoro'] 547 | \end{verbatim} 548 | 549 | Seperti contoh sebelumnya, list ini juga dapat diurutkan. Berikut ini 550 | contoh untuk mengurutkan dengan urutan terbalik. Perhatikan adanya 551 | pilihan ``reverse=True'' ketika kita memanggil fungsi {\em sorted}. 552 | 553 | \begin{verbatim} 554 | people_sorted = sorted(people, reverse=True) 555 | print(people_sorted) 556 | 557 | ['zoro', 'rudi', 'rahardjo', 'cecep', 'budi', 'ani', 'BUDI'] 558 | \end{verbatim} 559 | 560 | Sekarang kita akan mengubah semua huruf di dalam list tersebut 561 | menjadi huruf kecil. Untuk ini kita akan menggunakan sebuah fungsi 562 | yang kita buat sendiri. (Pembahasan tentang fungsi akan ada di 563 | tempat lain. Saat ini kita pakai saja tanpa perlu teori.) 564 | 565 | \begin{verbatim} 566 | def all_lower(my_list): 567 | return [x.lower() for x in my_list] 568 | print(all_lower(people)) 569 | 570 | ['budi', 'cecep', 'rudi', 'ani', 'budi', 'rahardjo', 'zoro'] 571 | \end{verbatim} 572 | 573 | Bagaimana jika kita ingin membuat huruf awal dari setiap nama (kata) 574 | memiliki huruf besar? Ini caranya. 575 | 576 | \begin{verbatim} 577 | people_lower = [x.lower() for x in people] 578 | people_cap = [x.capitalize() for x in people_lower] 579 | print(people_cap) 580 | 581 | ['Budi', 'Cecep', 'Rudi', 'Ani', 'Budi', 'Rahardjo', 'Zoro'] 582 | \end{verbatim} 583 | 584 | \section{Input} 585 | Salah satu cara untuk mendapatkan masukan (input) dari pengguna secara 586 | interaktif adalah dengan menggunakan fungsi "input". 587 | Apa yang Anda ketikkan akan dimasukkan ke dalam variabel sebagai string 588 | (teks). Jika Anda ingin mengubahnya menjadi angka, maka Anda harus 589 | melakukan hal ini secara eksplisit. 590 | 591 | \begin{verbatim} 592 | nama = input("Masukkan nama Anda: ") 593 | print("Selamat pagi,", nama) 594 | \end{verbatim} 595 | 596 | Perhatikan bahwa kita menggunakan variabel "nama" untuk menyimpan masukan 597 | dari pengguna. Variabel "nama" tersebut mempunyai tipe {\em string}. 598 | Python mengenali secara otomatis. 599 | 600 | Mari kita coba tampilkan huruf-huruf yang ada di dalam variabel "nama" 601 | tersebut. 602 | 603 | \begin{verbatim} 604 | # for loop bisa menggunakan elemen dari string 605 | # tidak harus indeks angka 606 | for i in nama: 607 | print i 608 | \end{verbatim} 609 | 610 | Kita juga dapat membuat statistik kemunculan huruf dari nama (atau teks) 611 | yang dimasukkan oleh pengguna. Statistik ini dapat dimanfaatkan untuk 612 | proses enkripsi, misalnya. Gunakan program "input" di atas, dan gabungkan 613 | dengan kode berikut ini. 614 | 615 | \begin{verbatim} 616 | # associative array: hitung jumlah huruf dan spasi 617 | huruf = {} # inisialisasi 618 | for key in nama: 619 | if key in huruf: 620 | huruf[key] += 1 621 | else: 622 | huruf[key]=1 623 | # tampilkan hasil python 2.7 624 | # sorted() agar key-nya diurutkan 625 | # for python 3.* use this: for key, value in d.items(): 626 | for key, value in sorted(huruf.iteritems()): 627 | print key, value 628 | \end{verbatim} 629 | 630 | Contoh program di atas menggunakan {\em associative array} atau dalam 631 | Python disebut {\em dictionary}. Pada prinsipnya ini adalah array tetapi 632 | dengan menggunakan {\em immutable object} seperti {\em string} sebagai 633 | indeks atau kuncinya. 634 | 635 | Pada contoh tersebut, spasi ({\em space}) masih dianggap sebagai huruf. 636 | Coba ubah sehingga spasi tidak dimasukkan sebagai indeks. 637 | 638 | Jika kita ingin data yang dimasukkan adalah berbentuk angka, integer misalnya, 639 | maka perlu dilakukan konversi secara eksplisit. 640 | Contoh berikut ini dapat menunjukkan hal tersebut. 641 | 642 | \begin{verbatim} 643 | a = input("a = ") 644 | b = input("b = ") 645 | c = a+b 646 | 647 | print("c =", c) 648 | print(int(a)+int(b)) 649 | \end{verbatim} 650 | 651 | Kode print yang pertama akan melakukan {\em concatenate} teks (string) yang 652 | Anda masukkan ke $a$ dan $b$. Ini dikarenakan input akan memberikan tipe 653 | data {\em string}. 654 | Untuk memastikan bahwa yang dijumlahkan adalah angka (dalam hal ini adalah 655 | bilang bulat atau integer) maka dilakukan konversi tipe data ke integer 656 | dengan perintah ``int(a)'', misalnya. 657 | Perjumlahan antara $int(a)$ dan $int(b)$ adalah perjumlahan bilangan bulat. 658 | 659 | 660 | \section{Pencabangan - Branching} 661 | Dalam pemrograman, salah satu yang sering dilakukan adalah memilih cabang 662 | (branch) berdasarkan sebuah kondisi. Misal jika sebuah variabel berisi 663 | nilai negatif maka program memilih jalur satu, selain itu program akan 664 | berjalan dengan memilih jalur kedua. 665 | Mari kita coba hal ini dengan sebuah contoh. 666 | 667 | \begin{verbatim} 668 | x = input("Masukkan bilangan antara -10 dan 10: "); 669 | z = int(x) 670 | if z < 0: 671 | print("Anda memasukkan bilangan negatif, ", z) 672 | else: 673 | print("Anda memasukkan bilangan positif, ", z) 674 | \end{verbatim} 675 | 676 | Di dalam bahasa Python, pencabangan dapat dilakukan dengan klausul 677 | ``if (kondisi):''. Jika kondisi tersebut benar (True) maka blok di 678 | bawahnya akan dieksekusi. 679 | Kondisi ini dapat ditambahkan juga dengan klausul ``else:'', 680 | yang mana jika kondisi tidak terpenuhi (False) maka blok di bawahnya 681 | akan dieksekusi. 682 | 683 | Pencabangan dapat dilakukan dengan lebih kompleks lagi jika pilihannya 684 | lebih dari satu. Bagian ``else'' dapat digantikan dengan ``elif'' 685 | yang merupakan kependekan dari ``else if''. 686 | 687 | 688 | 689 | \section{Pemrosesan Teks} 690 | Salah satu manfaat utama dari bahasa pemrograman seperti Python adalah 691 | kemampuannya dalam memproses teks ({\em text processing}). Bahasa 692 | pemrograman lainnya, seperti C, tentu saja dapat digunakan untuk melakukan 693 | pemrosesan teks. Namun bahasa C lebih "sulit" digunakan karena ada banyak 694 | hal yang harus kita ketahui dari awal. 695 | 696 | \begin{verbatim} 697 | # text processing 698 | # memecah kalimat menjadi kata-kata 699 | kalimat = raw_input("Masukkan kalimat yang cukup panjang.\n") 700 | # pisahkan menjadi kata 701 | kata = kalimat.split() 702 | for k in kata: 703 | print(k) 704 | \end{verbatim} 705 | 706 | Contoh singkat di atas menunjukkan cara memecahkan kalimat menjadi kata-kata. 707 | Sebagai catatan, kalimat yang dimaksudkan diakhiri dengan {\em return}. 708 | Untuk memproses kalimat yang lebih panjang dan memiliki {\em return} harus 709 | dilakukan perbaikan. 710 | Coba kembangkan program yang dapat menerima masukan dari sebuah berkas. 711 | 712 | Dengan menggunakan ide pada bagian sebelumnya, kita dapat menghitung 713 | jumlah kemunculan kata tertentu dalam sebuah kalimat. (Perhatikan bahwa 714 | "kata" di sini bersifat {\em case sensitive}. Agar dia tidak bergantung 715 | kepada huruf besar dan kecil, semua huruf harus diubah dahulu ke 716 | huruf kecil.) 717 | 718 | Program ini juga dapat menjadi basis dari sebuah sistem untuk menganalisis 719 | sentimen seseorang di media sosial. Pikirkan algoritmanya untuk melakukan 720 | hal tersebut. 721 | 722 | 723 | \section{Membaca Berkas: topic generator} 724 | Salah satu kegunaan utama bahasa {\em scripting} seperti Python adalah 725 | untuk memproses sebuah berkas. Kata-kata atau data dalam berkas tersebut 726 | dapat diproses seperti telah diuraikan pada bagian sebelumnya. 727 | 728 | Pada bagian ini kita akan melihat bagaimana membaca sebuah berkas teks. 729 | Agar lebih menarik, kita akan melakukannya dalam konteks sebuah aplikasi, 730 | yaitu ``topic generator''. Singkatnya aplikasi ini digunakan untuk 731 | mengusulkan sebuah topik yang dapat Anda bahas ketika Anda ingin 732 | menulis untuk sebuah blog (atau bahkan vlog). 733 | Jika dijalankan, dia akan memberikan sebuah topik kepada Anda. 734 | Sihir? Magic? Smart? 735 | 736 | Sesungguhnya aplikasi ini hanya membaca sebuah berkas yang berisi 737 | daftar topik-topik yang kita tulisakan sebelumnya. Kemudian dia 738 | akan memilih (secara random) salah satu dari topik tersebut. 739 | Jadi aplikasinya sangat sederhana. 740 | 741 | Berkas yang akan dibaca adalah sebuah berkas teks yang memiliki 742 | format sebagai berikut. Topik dan topik selanjutnya dipisahkan oleh 743 | baris yang berisi dua garis-garis (``---''). Contoh isi dari 744 | berkas ``topics.txt'' adalah seperti ini. 745 | Agar lebih fleksibel, topik dapat lebih dari satu baris. 746 | 747 | \begin{verbatim} 748 | Ceritakan tentang sepatu Anda 749 | -- 750 | Buku apa yang paling Anda sukai 751 | -- 752 | Binatang apa yang paling Anda sukai 753 | -- 754 | Ceritakan tentang pengalaman yang paling menyedihkan 755 | ketika Anda sekolah 756 | -- 757 | Buku (film) apa yang paling berkesan untuk Anda 758 | -- 759 | \end{verbatim} 760 | 761 | 762 | Ada banyak cara untuk membaca berkas teks seperti itu. 763 | Untuk berkas yang ukurannya kecil, kita dapat membaca keseluruhan 764 | berkas dalam satu perintah. Ini biasanya dikenal dengan istilah ``slurp''. 765 | Ada pro dan kontra soal itu. 766 | Ada sebuah artikel yang mengatakan bahwa kalau kita melakukan {\em slurping}, 767 | maka memori akan digunakan untuk data (betul) dan pembacaan 768 | akan membutuhkan waktu yang lebih lama\footnote{Saya baru tahu ini ketika 769 | menulis buku ini. Link menyusul.}. 770 | 771 | Kode untuk membaca berkas di atas, menyimpan topk dalam 772 | bentuk {\em list}, dan menampilkan salah satu topik tersebut 773 | secara random adalah sebagai berikut\footnote{Kode ini ada di 774 | https://github.com/rahard/BRcoding}. 775 | 776 | \begin{verbatim} 777 | topicfile = "topics.txt" 778 | 779 | # kata orang jangan di-slurp tapi dibaca perbaris seperti ini 780 | with open(topicfile, 'r+') as f: 781 | count = 1 782 | topic='' 783 | topics=[] 784 | for line in f: 785 | if (line == "--\n"): 786 | #print('{:>6} {}'.format(count, topic)) 787 | topics.append(topic) 788 | topic='' 789 | count += 1 790 | else: 791 | if (topic != ''): 792 | # append to previous line with a space 793 | topic = topic + ' ' + line[:-1] 794 | else: 795 | topic = topic + line[:-1] 796 | 797 | # rangkuman 798 | print("There are", len(topics), "topics") 799 | 800 | # pilih sebuah topik secara random 801 | import random 802 | n = random.randint(0,len(topics)-1) 803 | print(n, topics[n]) 804 | \end{verbatim} 805 | 806 | Kode ini dapat dijalankan dari CLI dan akan memilihkan salah satu 807 | topik secara random. 808 | Pada pembahasan yang lain, kita akan menggunakan kode ini dan 809 | menempatkannya dalam sebuah web dalam bentuk API. 810 | 811 | \section{Python3} 812 | Bagaimana caranya agar kita dapat menggunakan Python3 sebagai {\em default} 813 | dari Python?\footnote{Bagian ini masih ada karena ketika buku ini ditulis, 814 | Python yang digunakan adalah versi 2. Jika nanti Python versi 2 sudah 815 | benar-benar dianggap tidak ada dan umumnya orang sudah menggunakan 816 | versi 3, maka bagian ini akan dihilangkan.} 817 | Cara yang paling mudah adalah dengan menggunakan fitur 818 | alias di shell (jika Anda menggunakan variasi dari UNIX). 819 | 820 | \begin{verbatim} 821 | alias python=python3 822 | \end{verbatim} 823 | 824 | Jika Anda ingin membuat ini menjadi permanen dan Anda menggunakan {\em bash} 825 | sebagai shell Anda, letakkan alias tersebut pada berkas ``.bashrc'' pada 826 | {\em home directory} Anda (atau pada berkas ``.bash\_aliases''). 827 | Jika Anda menyimpannya di dalam berkas tersebut, maka perubahan baru akan 828 | terjadi jika Anda membuat sesi shell baru atau Anda logout dan login kembali. 829 | Jika Anda ingin langsung aktif, bisa juga berkas tersebut di-source. 830 | 831 | \begin{verbatim} 832 | source ~/.bashrc 833 | \end{verbatim} 834 | 835 | Untuk memasang modul-modul di Python3 dapat dilakukan dengan cara 836 | memanggil python3 secara eksplisit. Sebagai contoh, untuk memasang 837 | modul ``numpy'' pada (dengan) python3 adalah sebagai berikut. 838 | 839 | \begin{verbatim} 840 | python3 -m pip install numpy 841 | \end{verbatim} 842 | 843 | Sebagai catatan ada banyak cara untuk memasang modul Python, tetapi 844 | cara di atas yang paling konsisten bagi saya. 845 | -------------------------------------------------------------------------------- /pengantar.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\zref@newlabel[2]{} 4 | \@setckpt{pengantar}{ 5 | \setcounter{page}{6} 6 | \setcounter{equation}{0} 7 | \setcounter{enumi}{0} 8 | \setcounter{enumii}{0} 9 | \setcounter{enumiii}{0} 10 | \setcounter{enumiv}{0} 11 | \setcounter{footnote}{0} 12 | \setcounter{mpfootnote}{0} 13 | \setcounter{part}{0} 14 | \setcounter{chapter}{0} 15 | \setcounter{section}{0} 16 | \setcounter{subsection}{0} 17 | \setcounter{subsubsection}{0} 18 | \setcounter{paragraph}{0} 19 | \setcounter{subparagraph}{0} 20 | \setcounter{figure}{0} 21 | \setcounter{table}{0} 22 | \setcounter{Item}{0} 23 | \setcounter{bookmark@seq@number}{0} 24 | \setcounter{cp@cntr}{0} 25 | \setcounter{NAT@ctr}{0} 26 | \setcounter{@tufte@num@bibkeys}{0} 27 | \setcounter{Exercise}{0} 28 | \setcounter{Answer}{0} 29 | \setcounter{ExePart}{0} 30 | \setcounter{Question}{0} 31 | \setcounter{subQuestion}{0} 32 | \setcounter{subsubQuestion}{0} 33 | \setcounter{savedQuestion}{0} 34 | \setcounter{savedsubQuestion}{0} 35 | \setcounter{savedsubsubQuestion}{0} 36 | \setcounter{mdf@globalstyle@cnt}{0} 37 | \setcounter{mdfcountframes}{0} 38 | \setcounter{mdf@env@i}{0} 39 | \setcounter{mdf@env@ii}{0} 40 | \setcounter{mdf@zref@counter}{0} 41 | \setcounter{parentequation}{0} 42 | \setcounter{@pps}{0} 43 | \setcounter{@ppsavesec}{0} 44 | \setcounter{@ppsaveapp}{0} 45 | \setcounter{section@level}{0} 46 | } 47 | -------------------------------------------------------------------------------- /pengantar.tex: -------------------------------------------------------------------------------- 1 | \chapter*{Pengantar} 2 | Buku ini sebetulnya merupakan catatan pribadi saya dalam belajar pemrograman 3 | dengan menggunakan bahasa Python. Saya sudah mengenal Python sejak dari jaman 4 | dahulu kala, tetapi pada masa itu saya tidak terlalu tertarik karena saya lebih 5 | suka menggunakan bahasa Perl. Sampai sekarang sebetulnya saya masih suka 6 | menggunakan bahasa Perl, tetapi karena tuntutan zaman yang banyak membutuhkan 7 | pemrograman dengan menggunakan bahasa Python maka saya kembali mempelajari 8 | bahasa Python. 9 | 10 | Buku ini lebih banyak menampilkan contoh-contoh yang saya gunakan untuk 11 | mengingat-ingat hal-hal yang pernah saya kerjakan atau untuk mencari ide ketika 12 | memecahkan masalah lain. Jadinya buku ini seperti sebuah {\em cookbook}. Semoga 13 | pendekatan seperti ini cocok juga untuk Anda. 14 | 15 | Yang namanya catatan tentu saja sesuai dengan apa yang saya lakukan. Basis saya 16 | menggunakan Linux. Jadi ada kemungkinan contoh yang tidak persis sama. Demikian 17 | pula cara saya menggunakan (memprogram dengan) Python mungkin bukan cara yang 18 | paling sempurna, tetapi mengikuti cara saya. (Apapun itu.) 19 | 20 | \st{Ketika buku ini ditulis, versi Python yang paling stabil adalah versi 2.7 21 | meskipun versi 3 juga sudah banyak digunakan orang. Ada banyak bagian di dalam 22 | buku ini yang dituliskan untuk Python versi 2.7 kemungkinan harus disesuaikan 23 | untuk versi 3. Sebagai contoh, print harus menggunakan tanda kurung. 24 | Namun secara prinsip mestinya sebagian besar akan tetap sama.} 25 | 26 | Versi buku ini sudah menganjurkan untuk lebih condong ke Python versi 3 27 | karena pengembangan versi 2 sudah mulai dihentikan. 28 | [Catatan: buku mulai ditulis akhir 2017.] 29 | Bagian-bagian yang sudah terlanjur ditulis dengan menggunakan versi 2, 30 | sedikit demi sedikit mulai diubah ke versi 3 dan hal-hal yang terkait 31 | dengan versi 2, mulai dihapuskan. 32 | 33 | 34 | Selamat menikmati versi 0.95\\ 35 | Bandung, Oktober 2024 \\ 36 | Budi Rahardjo 37 | -------------------------------------------------------------------------------- /python.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\zref@newlabel[2]{} 4 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} 5 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined 6 | \global\let\oldcontentsline\contentsline 7 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} 8 | \global\let\oldnewlabel\newlabel 9 | \gdef\newlabel#1#2{\newlabelxx{#1}#2} 10 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} 11 | \AtEndDocument{\ifx\hyper@anchor\@undefined 12 | \let\contentsline\oldcontentsline 13 | \let\newlabel\oldnewlabel 14 | \fi} 15 | \fi} 16 | \global\let\hyper@last\relax 17 | \gdef\HyperFirstAtBeginDocument#1{#1} 18 | \providecommand\HyField@AuxAddToFields[1]{} 19 | \providecommand\HyField@AuxAddToCoFields[2]{} 20 | \@input{pengantar.aux} 21 | \@input{pendahuluan.aux} 22 | \@input{advanced.aux} 23 | \@input{tricks.aux} 24 | \bibdata{referensi} 25 | \bibcite{tensorflowstarted}{{1}{}{{}}{{}}} 26 | \bibstyle{plain} 27 | \providecommand\NAT@force@numbers{}\NAT@force@numbers 28 | \@writefile{toc}{\contentsline {chapter}{\numberline {4}Bibliography}{45}{chapter.4}\protected@file@percent } 29 | \@writefile{lof}{\addvspace {10\p@ }} 30 | \@writefile{lot}{\addvspace {10\p@ }} 31 | \ttl@finishall 32 | \newlabel{TotPages}{{45}{45}{}{page.45}{}} 33 | \gdef \@abspage@last{45} 34 | -------------------------------------------------------------------------------- /python.bbl: -------------------------------------------------------------------------------- 1 | \begin{thebibliography}{1} 2 | 3 | \bibitem{tensorflowstarted} 4 | Giancarlo Zaccone. 5 | \newblock {\em Getting Started with Tensorflow}. 6 | \newblock Packt Publishing, 2016. 7 | 8 | \end{thebibliography} 9 | -------------------------------------------------------------------------------- /python.blg: -------------------------------------------------------------------------------- 1 | This is BibTeX, Version 0.99d (TeX Live 2015/Debian) 2 | Capacity: max_strings=35307, hash_size=35307, hash_prime=30011 3 | The top-level auxiliary file: python.aux 4 | A level-1 auxiliary file: pengantar.aux 5 | A level-1 auxiliary file: pendahuluan.aux 6 | A level-1 auxiliary file: advanced.aux 7 | A level-1 auxiliary file: tricks.aux 8 | The style file: plain.bst 9 | Database file #1: referensi.bib 10 | You've used 1 entry, 11 | 2118 wiz_defined-function locations, 12 | 506 strings with 4129 characters, 13 | and the built_in function-call counts, 235 in all, are: 14 | = -- 19 15 | > -- 7 16 | < -- 0 17 | + -- 3 18 | - -- 2 19 | * -- 10 20 | := -- 47 21 | add.period$ -- 3 22 | call.type$ -- 1 23 | change.case$ -- 3 24 | chr.to.int$ -- 0 25 | cite$ -- 1 26 | duplicate$ -- 12 27 | empty$ -- 23 28 | format.name$ -- 2 29 | if$ -- 47 30 | int.to.chr$ -- 0 31 | int.to.str$ -- 1 32 | missing$ -- 2 33 | newline$ -- 8 34 | num.names$ -- 2 35 | pop$ -- 8 36 | preamble$ -- 1 37 | purify$ -- 3 38 | quote$ -- 0 39 | skip$ -- 6 40 | stack$ -- 0 41 | substring$ -- 5 42 | swap$ -- 1 43 | text.length$ -- 0 44 | text.prefix$ -- 0 45 | top$ -- 0 46 | type$ -- 2 47 | warning$ -- 0 48 | while$ -- 2 49 | width$ -- 2 50 | write$ -- 12 51 | -------------------------------------------------------------------------------- /python.idx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/python.idx -------------------------------------------------------------------------------- /python.log: -------------------------------------------------------------------------------- 1 | This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) (preloaded format=pdflatex 2024.10.19) 20 OCT 2024 12:16 2 | entering extended mode 3 | restricted \write18 enabled. 4 | %&-line parsing enabled. 5 | **python.tex 6 | (./python.tex 7 | LaTeX2e <2021-11-15> patch level 1 8 | L3 programming layer <2022-01-21> (./tufte-book.cls 9 | Document Class: tufte-book 2015/06/30 v3.5.3 Tufte-book class 10 | (./tufte-common.def 11 | File: tufte-common.def 2015/06/21 v3.5.2 Common code for the Tufte-LaTeX styles 12 | 13 | 14 | (/usr/share/texlive/texmf-dist/tex/latex/xkeyval/xkeyval.sty 15 | Package: xkeyval 2020/11/20 v2.8 package option processing (HA) 16 | 17 | (/usr/share/texlive/texmf-dist/tex/generic/xkeyval/xkeyval.tex 18 | (/usr/share/texlive/texmf-dist/tex/generic/xkeyval/xkvutils.tex 19 | \XKV@toks=\toks16 20 | \XKV@tempa@toks=\toks17 21 | 22 | (/usr/share/texlive/texmf-dist/tex/generic/xkeyval/keyval.tex)) 23 | \XKV@depth=\count185 24 | File: xkeyval.tex 2014/12/03 v2.7a key=value parser (HA) 25 | )) 26 | (/usr/share/texlive/texmf-dist/tex/latex/xifthen/xifthen.sty 27 | Package: xifthen 2015/11/05 v1.4.0 Extended ifthen features 28 | 29 | (/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty 30 | Package: calc 2017/05/25 v4.3 Infix arithmetic (KKT,FJ) 31 | \calc@Acount=\count186 32 | \calc@Bcount=\count187 33 | \calc@Adimen=\dimen138 34 | \calc@Bdimen=\dimen139 35 | \calc@Askip=\skip47 36 | \calc@Bskip=\skip48 37 | LaTeX Info: Redefining \setlength on input line 80. 38 | LaTeX Info: Redefining \addtolength on input line 81. 39 | \calc@Ccount=\count188 40 | \calc@Cskip=\skip49 41 | ) 42 | (/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty 43 | Package: ifthen 2020/11/24 v1.1c Standard LaTeX ifthen package (DPC) 44 | ) 45 | (/usr/share/texlive/texmf-dist/tex/latex/ifmtarg/ifmtarg.sty 46 | Package: ifmtarg 2018/04/16 v1.2b check for an empty argument 47 | )) 48 | (/usr/share/texlive/texmf-dist/tex/latex/hardwrap/hardwrap.sty 49 | Package: hardwrap 2011/02/12 v0.2 Hard wrap messages 50 | 51 | (/usr/share/texlive/texmf-dist/tex/latex/ifplatform/ifplatform.sty 52 | Package: ifplatform 2017/10/13 v0.4a Testing for the operating system 53 | 54 | (/usr/share/texlive/texmf-dist/tex/latex/tools/shellesc.sty 55 | Package: shellesc 2019/11/08 v1.0c unified shell escape interface for LaTeX 56 | Package shellesc Info: Restricted shell escape enabled on input line 77. 57 | ) 58 | (/usr/share/texlive/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty 59 | Package: pdftexcmds 2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO 60 | ) 61 | 62 | (/usr/share/texlive/texmf-dist/tex/generic/infwarerr/infwarerr.sty 63 | Package: infwarerr 2019/12/03 v1.5 Providing info/warning/error messages (HO) 64 | ) 65 | (/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty 66 | Package: iftex 2020/03/06 v1.0d TeX engine tests 67 | ) 68 | (/usr/share/texlive/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty 69 | Package: ltxcmds 2020-05-10 v1.25 LaTeX kernel commands for general use (HO) 70 | ) 71 | Package pdftexcmds Info: \pdf@primitive is available. 72 | Package pdftexcmds Info: \pdf@ifprimitive is available. 73 | Package pdftexcmds Info: \pdfdraftmode found. 74 | ) 75 | (/usr/share/texlive/texmf-dist/tex/generic/catchfile/catchfile.sty 76 | Package: catchfile 2019/12/09 v1.8 Catch the contents of a file (HO) 77 | 78 | (/usr/share/texlive/texmf-dist/tex/generic/etexcmds/etexcmds.sty 79 | Package: etexcmds 2019/12/15 v1.7 Avoid name clashes with e-TeX commands (HO) 80 | )) 81 | (/usr/share/texlive/texmf-dist/tex/generic/iftex/ifluatex.sty 82 | Package: ifluatex 2019/10/25 v1.5 ifluatex legacy package. Use iftex instead. 83 | ) 84 | 85 | Package ifplatform Warning: 86 | shell escape is disabled, so I can only detect \ifwindows. 87 | 88 | ) (/usr/share/texlive/texmf-dist/tex/generic/iftex/ifxetex.sty 89 | Package: ifxetex 2019/10/25 v0.7 ifxetex legacy package. Use iftex instead. 90 | ) 91 | \hw@charcount=\count189 92 | \hw@wordcount=\count190 93 | \hw@maxprintline=\count191 94 | 95 | (|kpsewhich -var-value=max_print_line)) 96 | Class tufte-book Info: Loading the base class `book' 97 | 98 | (/usr/share/texlive/texmf-dist/tex/latex/base/book.cls 99 | Document Class: book 2021/10/04 v1.4n Standard LaTeX document class 100 | (/usr/share/texlive/texmf-dist/tex/latex/base/bk10.clo 101 | File: bk10.clo 2021/10/04 v1.4n Standard LaTeX file (size option) 102 | ) 103 | \c@part=\count192 104 | \c@chapter=\count193 105 | \c@section=\count194 106 | \c@subsection=\count195 107 | \c@subsubsection=\count196 108 | \c@paragraph=\count197 109 | \c@subparagraph=\count198 110 | \c@figure=\count199 111 | \c@table=\count266 112 | \abovecaptionskip=\skip50 113 | \belowcaptionskip=\skip51 114 | \bibindent=\dimen140 115 | ) 116 | (/usr/share/texlive/texmf-dist/tex/generic/iftex/ifpdf.sty 117 | Package: ifpdf 2019/10/25 v3.4 ifpdf legacy package. Use iftex instead. 118 | ) 119 | (/usr/share/texlive/texmf-dist/tex/latex/titlesec/titlesec.sty 120 | Package: titlesec 2021/07/05 v2.14 Sectioning titles 121 | \ttl@box=\box50 122 | \beforetitleunit=\skip52 123 | \aftertitleunit=\skip53 124 | \ttl@plus=\dimen141 125 | \ttl@minus=\dimen142 126 | \ttl@toksa=\toks18 127 | \titlewidth=\dimen143 128 | \titlewidthlast=\dimen144 129 | \titlewidthfirst=\dimen145 130 | ) 131 | (/usr/share/texlive/texmf-dist/tex/latex/titlesec/titletoc.sty 132 | Package: titletoc 2021/07/05 v2.14 TOC entries 133 | \ttl@leftsep=\dimen146 134 | ) 135 | (/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty 136 | Package: hyperref 2021-06-07 v7.00m Hypertext links for LaTeX 137 | 138 | (/usr/share/texlive/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty 139 | Package: kvsetkeys 2019/12/15 v1.18 Key value parser (HO) 140 | ) 141 | (/usr/share/texlive/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty 142 | Package: kvdefinekeys 2019-12-19 v1.6 Define keys (HO) 143 | ) 144 | (/usr/share/texlive/texmf-dist/tex/generic/pdfescape/pdfescape.sty 145 | Package: pdfescape 2019/12/09 v1.15 Implements pdfTeX's escape features (HO) 146 | ) 147 | (/usr/share/texlive/texmf-dist/tex/latex/hycolor/hycolor.sty 148 | Package: hycolor 2020-01-27 v1.10 Color options for hyperref/bookmark (HO) 149 | ) 150 | (/usr/share/texlive/texmf-dist/tex/latex/letltxmacro/letltxmacro.sty 151 | Package: letltxmacro 2019/12/03 v1.6 Let assignment for LaTeX macros (HO) 152 | ) 153 | (/usr/share/texlive/texmf-dist/tex/latex/auxhook/auxhook.sty 154 | Package: auxhook 2019-12-17 v1.6 Hooks for auxiliary files (HO) 155 | ) 156 | (/usr/share/texlive/texmf-dist/tex/latex/kvoptions/kvoptions.sty 157 | Package: kvoptions 2020-10-07 v3.14 Key value format for package options (HO) 158 | ) 159 | \@linkdim=\dimen147 160 | \Hy@linkcounter=\count267 161 | \Hy@pagecounter=\count268 162 | 163 | (/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def 164 | File: pd1enc.def 2021-06-07 v7.00m Hyperref: PDFDocEncoding definition (HO) 165 | Now handling font encoding PD1 ... 166 | ... no UTF-8 mapping file for font encoding PD1 167 | ) 168 | (/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref-langpatches.def 169 | File: hyperref-langpatches.def 2021-06-07 v7.00m Hyperref: patches for babel la 170 | nguages 171 | ) 172 | (/usr/share/texlive/texmf-dist/tex/generic/intcalc/intcalc.sty 173 | Package: intcalc 2019/12/15 v1.3 Expandable calculations with integers (HO) 174 | ) 175 | \Hy@SavedSpaceFactor=\count269 176 | 177 | (/usr/share/texlive/texmf-dist/tex/latex/hyperref/puenc.def 178 | File: puenc.def 2021-06-07 v7.00m Hyperref: PDF Unicode definition (HO) 179 | Now handling font encoding PU ... 180 | ... no UTF-8 mapping file for font encoding PU 181 | ) 182 | Package hyperref Info: Option `unicode' set `true' on input line 4073. 183 | Package hyperref Info: Option `hyperfootnotes' set `false' on input line 4073. 184 | Package hyperref Info: Hyper figures OFF on input line 4192. 185 | Package hyperref Info: Link nesting OFF on input line 4197. 186 | Package hyperref Info: Hyper index ON on input line 4200. 187 | Package hyperref Info: Plain pages OFF on input line 4207. 188 | Package hyperref Info: Backreferencing OFF on input line 4212. 189 | Package hyperref Info: Implicit mode ON; LaTeX internals redefined. 190 | Package hyperref Info: Bookmarks ON on input line 4445. 191 | \c@Hy@tempcnt=\count270 192 | 193 | (/usr/share/texlive/texmf-dist/tex/latex/url/url.sty 194 | \Urlmuskip=\muskip16 195 | Package: url 2013/09/16 ver 3.4 Verb mode for urls, etc. 196 | ) 197 | LaTeX Info: Redefining \url on input line 4804. 198 | \XeTeXLinkMargin=\dimen148 199 | 200 | (/usr/share/texlive/texmf-dist/tex/generic/bitset/bitset.sty 201 | Package: bitset 2019/12/09 v1.3 Handle bit-vector datatype (HO) 202 | 203 | (/usr/share/texlive/texmf-dist/tex/generic/bigintcalc/bigintcalc.sty 204 | Package: bigintcalc 2019/12/15 v1.5 Expandable calculations on big integers (HO 205 | ) 206 | )) 207 | \Fld@menulength=\count271 208 | \Field@Width=\dimen149 209 | \Fld@charsize=\dimen150 210 | Package hyperref Info: Hyper figures OFF on input line 6076. 211 | Package hyperref Info: Link nesting OFF on input line 6081. 212 | Package hyperref Info: Hyper index ON on input line 6084. 213 | Package hyperref Info: backreferencing OFF on input line 6091. 214 | Package hyperref Info: Link coloring OFF on input line 6096. 215 | Package hyperref Info: Link coloring with OCG OFF on input line 6101. 216 | Package hyperref Info: PDF/A mode OFF on input line 6106. 217 | LaTeX Info: Redefining \ref on input line 6146. 218 | LaTeX Info: Redefining \pageref on input line 6150. 219 | 220 | (/usr/share/texlive/texmf-dist/tex/latex/base/atbegshi-ltx.sty 221 | Package: atbegshi-ltx 2021/01/10 v1.0c Emulation of the original atbegshi 222 | package with kernel methods 223 | ) 224 | \Hy@abspage=\count272 225 | \c@Item=\count273 226 | ) 227 | Package hyperref Info: Driver (autodetected): hpdftex. 228 | 229 | (/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def 230 | File: hpdftex.def 2021-06-07 v7.00m Hyperref driver for pdfTeX 231 | 232 | (/usr/share/texlive/texmf-dist/tex/latex/base/atveryend-ltx.sty 233 | Package: atveryend-ltx 2020/08/19 v1.0a Emulation of the original atveryend pac 234 | kage 235 | with kernel methods 236 | ) 237 | \Fld@listcount=\count274 238 | \c@bookmark@seq@number=\count275 239 | 240 | (/usr/share/texlive/texmf-dist/tex/latex/rerunfilecheck/rerunfilecheck.sty 241 | Package: rerunfilecheck 2019/12/05 v1.9 Rerun checks for auxiliary files (HO) 242 | 243 | (/usr/share/texlive/texmf-dist/tex/generic/uniquecounter/uniquecounter.sty 244 | Package: uniquecounter 2019/12/15 v1.4 Provide unlimited unique counter (HO) 245 | ) 246 | Package uniquecounter Info: New unique counter `rerunfilecheck' on input line 2 247 | 86. 248 | ) 249 | \Hy@SectionHShift=\skip54 250 | ) 251 | (/usr/share/texlive/texmf-dist/tex/latex/ragged2e/ragged2e.sty 252 | Package: ragged2e 2021/12/15 v3.1 ragged2e Package 253 | \CenteringLeftskip=\skip55 254 | \RaggedLeftLeftskip=\skip56 255 | \RaggedRightLeftskip=\skip57 256 | \CenteringRightskip=\skip58 257 | \RaggedLeftRightskip=\skip59 258 | \RaggedRightRightskip=\skip60 259 | \CenteringParfillskip=\skip61 260 | \RaggedLeftParfillskip=\skip62 261 | \RaggedRightParfillskip=\skip63 262 | \JustifyingParfillskip=\skip64 263 | \CenteringParindent=\skip65 264 | \RaggedLeftParindent=\skip66 265 | \RaggedRightParindent=\skip67 266 | \JustifyingParindent=\skip68 267 | ) 268 | (/usr/share/texlive/texmf-dist/tex/latex/geometry/geometry.sty 269 | Package: geometry 2020/01/02 v5.9 Page Geometry 270 | 271 | (/usr/share/texlive/texmf-dist/tex/generic/iftex/ifvtex.sty 272 | Package: ifvtex 2019/10/25 v1.7 ifvtex legacy package. Use iftex instead. 273 | ) 274 | \Gm@cnth=\count276 275 | \Gm@cntv=\count277 276 | \c@Gm@tempcnt=\count278 277 | \Gm@bindingoffset=\dimen151 278 | \Gm@wd@mp=\dimen152 279 | \Gm@odd@mp=\dimen153 280 | \Gm@even@mp=\dimen154 281 | \Gm@layoutwidth=\dimen155 282 | \Gm@layoutheight=\dimen156 283 | \Gm@layouthoffset=\dimen157 284 | \Gm@layoutvoffset=\dimen158 285 | \Gm@dimlist=\toks19 286 | ) 287 | (/usr/share/texlive/texmf-dist/tex/latex/changepage/changepage.sty 288 | Package: changepage 2009/10/20 v1.0c check page and change page layout 289 | \c@cp@cntr=\count279 290 | \cp@tempcnt=\count280 291 | ) 292 | \@tufte@overhang=\skip69 293 | \@tufte@fullwidth=\skip70 294 | \@tufte@caption@fill=\skip71 295 | 296 | (/usr/share/texlive/texmf-dist/tex/latex/paralist/paralist.sty 297 | Package: paralist 2017/01/22 v2.7 Extended list environments 298 | \pltopsep=\skip72 299 | \plpartopsep=\skip73 300 | \plitemsep=\skip74 301 | \plparsep=\skip75 302 | \pl@lab=\toks20 303 | ) 304 | (/usr/share/texlive/texmf-dist/tex/latex/textcase/textcase.sty 305 | Package: textcase 2019/09/14 v1.00 Text only upper/lower case changing (DPC) 306 | ) 307 | (/usr/share/texlive/texmf-dist/tex/latex/microtype/letterspace.sty 308 | Package: letterspace 2021/12/10 v3.0b Robust letterspacing (RS) 309 | LaTeX Info: Redefining \lsstyle on input line 340. 310 | LaTeX Info: Redefining \lslig on input line 341. 311 | LaTeX Info: Redefining \textls on input line 366. 312 | \MT@outer@kern=\dimen159 313 | ) 314 | (/usr/share/texlive/texmf-dist/tex/latex/setspace/setspace.sty 315 | Package: setspace 2011/12/19 v6.7a set line spacing 316 | ) 317 | (/usr/share/texlive/texmf-dist/tex/latex/xcolor/xcolor.sty 318 | Package: xcolor 2021/10/31 v2.13 LaTeX color extensions (UK) 319 | 320 | (/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg 321 | File: color.cfg 2016/01/02 v1.6 sample color configuration 322 | ) 323 | Package xcolor Info: Driver file: pdftex.def on input line 227. 324 | 325 | (/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def 326 | File: pdftex.def 2020/10/05 v1.2a Graphics/color driver for pdftex 327 | ) 328 | Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1352. 329 | Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1356. 330 | Package xcolor Info: Model `RGB' extended on input line 1368. 331 | Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1370. 332 | Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1371. 333 | Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1372. 334 | Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1373. 335 | Package xcolor Info: Model `Gray' substituted by `gray' on input line 1374. 336 | Package xcolor Info: Model `wave' substituted by `hsb' on input line 1375. 337 | 338 | (/usr/share/texlive/texmf-dist/tex/latex/graphics/dvipsnam.def 339 | File: dvipsnam.def 2016/06/17 v3.0m Driver-dependent file (DPC,SPQR) 340 | ) 341 | (/usr/share/texlive/texmf-dist/tex/latex/xcolor/svgnam.def 342 | File: svgnam.def 2021/10/31 v2.13 Predefined colors according to SVG 1.1 (UK) 343 | )) 344 | (/usr/share/texlive/texmf-dist/tex/latex/natbib/natbib.sty 345 | Package: natbib 2010/09/13 8.31b (PWD, AO) 346 | \bibhang=\skip76 347 | \bibsep=\skip77 348 | LaTeX Info: Redefining \cite on input line 694. 349 | \c@NAT@ctr=\count281 350 | ) 351 | (/usr/share/texlive/texmf-dist/tex/latex/natbib/bibentry.sty 352 | Package: bibentry 2007/10/30 1.5 (PWD) 353 | ) (./python.bbl) 354 | \c@@tufte@num@bibkeys=\count282 355 | 356 | (./optparams.sty 357 | Package: optparams 2004/08/14 v0.9 multiple optional parameters in macros 358 | ) 359 | \@tufte@sidenote@vertical@offset=\skip78 360 | 361 | (/usr/share/texlive/texmf-dist/tex/latex/placeins/placeins.sty 362 | Package: placeins 2005/04/18 v 2.2 363 | ) 364 | \@tufte@margin@floatbox=\box51 365 | \@tufte@figure@box=\box52 366 | \@tufte@caption@box=\box53 367 | \@tufte@caption@vertical@offset=\skip79 368 | \@tufte@float@contents@width=\skip80 369 | 370 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/mathpazo.sty 371 | Package: mathpazo 2020/03/25 PSNFSS-v9.3 Palatino w/ Pazo Math (D.Puga, WaS) 372 | \symupright=\mathgroup4 373 | ) 374 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/helvet.sty 375 | Package: helvet 2020/03/25 PSNFSS-v9.3 (WaS) 376 | ) 377 | (/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty 378 | Package: fontenc 2021/04/29 v2.0v Standard LaTeX package 379 | LaTeX Font Info: Trying to load font information for T1+pplj on input line 1 380 | 12. 381 | 382 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/t1pplj.fd 383 | File: t1pplj.fd 2004/09/06 font definitions for T1/pplj. 384 | )) 385 | (/usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty 386 | Package: textcomp 2020/02/02 v2.0n Standard LaTeX package 387 | ) 388 | (/usr/share/texlive/texmf-dist/tex/latex/fancyhdr/fancyhdr.sty 389 | Package: fancyhdr 2021/01/28 v4.0.1 Extensive control of page headers and foote 390 | rs 391 | \f@nch@headwidth=\skip81 392 | \f@nch@O@elh=\skip82 393 | \f@nch@O@erh=\skip83 394 | \f@nch@O@olh=\skip84 395 | \f@nch@O@orh=\skip85 396 | \f@nch@O@elf=\skip86 397 | \f@nch@O@erf=\skip87 398 | \f@nch@O@olf=\skip88 399 | \f@nch@O@orf=\skip89 400 | ) 401 | \tufteskipamount=\skip90 402 | 403 | (/usr/share/texlive/texmf-dist/tex/latex/tools/multicol.sty 404 | Package: multicol 2021/10/28 v1.9b multicolumn formatting (FMi) 405 | \c@tracingmulticols=\count283 406 | \mult@box=\box54 407 | \multicol@leftmargin=\dimen160 408 | \c@unbalance=\count284 409 | \c@collectmore=\count285 410 | \doublecol@number=\count286 411 | \multicoltolerance=\count287 412 | \multicolpretolerance=\count288 413 | \full@width=\dimen161 414 | \page@free=\dimen162 415 | \premulticols=\dimen163 416 | \postmulticols=\dimen164 417 | \multicolsep=\skip91 418 | \multicolbaselineskip=\skip92 419 | \partial@page=\box55 420 | \last@line=\box56 421 | \maxbalancingoverflow=\dimen165 422 | \mult@rightbox=\box57 423 | \mult@grightbox=\box58 424 | \mult@firstbox=\box59 425 | \mult@gfirstbox=\box60 426 | \@tempa=\box61 427 | \@tempa=\box62 428 | \@tempa=\box63 429 | \@tempa=\box64 430 | \@tempa=\box65 431 | \@tempa=\box66 432 | \@tempa=\box67 433 | \@tempa=\box68 434 | \@tempa=\box69 435 | \@tempa=\box70 436 | \@tempa=\box71 437 | \@tempa=\box72 438 | \@tempa=\box73 439 | \@tempa=\box74 440 | \@tempa=\box75 441 | \@tempa=\box76 442 | \@tempa=\box77 443 | \@tempa=\box78 444 | \@tempa=\box79 445 | \@tempa=\box80 446 | \@tempa=\box81 447 | \@tempa=\box82 448 | \@tempa=\box83 449 | \@tempa=\box84 450 | \@tempa=\box85 451 | \@tempa=\box86 452 | \@tempa=\box87 453 | \@tempa=\box88 454 | \@tempa=\box89 455 | \@tempa=\box90 456 | \@tempa=\box91 457 | \@tempa=\box92 458 | \@tempa=\box93 459 | \@tempa=\box94 460 | \@tempa=\box95 461 | \@tempa=\box96 462 | \c@minrows=\count289 463 | \c@columnbadness=\count290 464 | \c@finalcolumnbadness=\count291 465 | \last@try=\dimen166 466 | \multicolovershoot=\dimen167 467 | \multicolundershoot=\dimen168 468 | \mult@nat@firstbox=\box97 469 | \colbreak@box=\box98 470 | \mc@col@check@num=\count292 471 | ))) 472 | (/usr/share/texlive/texmf-dist/tex/latex/doclicense/doclicense.sty 473 | Package: doclicense 2021/07/11 v3.0.0 Support for putting documents under a lic 474 | ense 475 | 476 | (/usr/share/texlive/texmf-dist/tex/generic/xstring/xstring.sty 477 | (/usr/share/texlive/texmf-dist/tex/generic/xstring/xstring.tex 478 | \integerpart=\count293 479 | \decimalpart=\count294 480 | ) 481 | Package: xstring 2021/07/21 v1.84 String manipulations (CT) 482 | ) 483 | (/usr/share/texlive/texmf-dist/tex/latex/etoolbox/etoolbox.sty 484 | Package: etoolbox 2020/10/05 v2.5k e-TeX tools for LaTeX (JAW) 485 | \etb@tempcnta=\count295 486 | ) 487 | (/usr/share/texlive/texmf-dist/tex/latex/tools/xspace.sty 488 | Package: xspace 2014/10/28 v1.13 Space after command names (DPC,MH) 489 | ) 490 | (/usr/share/texlive/texmf-dist/tex/latex/tools/verbatim.sty 491 | Package: verbatim 2020-07-07 v1.5u LaTeX2e package for verbatim enhancements 492 | \every@verbatim=\toks21 493 | \verbatim@line=\toks22 494 | \verbatim@in@stream=\read2 495 | ) 496 | (/usr/share/texlive/texmf-dist/tex/latex/hyperxmp/hyperxmp.sty 497 | Package: hyperxmp 2020/11/22 v5.9 Store hyperref metadata in XMP format 498 | \hyxmp@aep@toks=\toks23 499 | 500 | (/usr/share/texlive/texmf-dist/tex/generic/stringenc/stringenc.sty 501 | Package: stringenc 2019/11/29 v1.12 Convert strings between diff. encodings (HO 502 | ) 503 | ) 504 | (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/ifdraft.sty 505 | Package: ifdraft 2016/05/16 v1.4 Detect class options draft and final (HO) 506 | ) 507 | (/usr/share/texlive/texmf-dist/tex/latex/totpages/totpages.sty 508 | Package: totpages 2005/09/19 v2.00 Totpages Package (muewi) 509 | 510 | (/usr/share/texlive/texmf-dist/tex/latex/everyshi/everyshi.sty 511 | Package: everyshi 2020/11/18 v4.00 EveryShipout Package 512 | ))) 513 | \doclicense@hsize=\skip93 514 | 515 | (/usr/share/texlive/texmf-dist/tex/latex/doclicense/doclicense-english.ldf 516 | File: doclicense-english.ldf 517 | )) 518 | (/usr/share/texlive/texmf-dist/tex/latex/exercise/exercise.sty 519 | Package: exercise 2014/10/20 v1.6 Exercise package (P.Pichaureau) 520 | \ExerciseSkipBefore=\skip94 521 | \ExerciseSkipAfter=\skip95 522 | \AnswerSkipBefore=\skip96 523 | \AnswerSkipAfter=\skip97 524 | \Exesep=\skip98 525 | \Exetopsep=\skip99 526 | \Exeparsep=\skip100 527 | \Exepartopsep=\skip101 528 | \Exeleftmargin=\skip102 529 | \Exerightmargin=\skip103 530 | \Exelabelwidth=\skip104 531 | \Exelabelsep=\skip105 532 | \ExerciseBefore=\skip106 533 | \QuestionBefore=\skip107 534 | \subQuestionBefore=\skip108 535 | \subsubQuestionBefore=\skip109 536 | \QuestionIndent=\skip110 537 | \subQuestionIndent=\skip111 538 | \subsubQuestionIndent=\skip112 539 | \c@Exercise=\count296 540 | \c@Answer=\count297 541 | \c@ExePart=\count298 542 | \c@Question=\count299 543 | \c@subQuestion=\count300 544 | \c@subsubQuestion=\count301 545 | \c@savedQuestion=\count302 546 | \c@savedsubQuestion=\count303 547 | \c@savedsubsubQuestion=\count304 548 | \@QuestionLevel=\count305 549 | \@Exercisebox=\box99 550 | \all@Exercisebox=\box100 551 | \temp@Exercisebox=\box101 552 | \all@Answerbox=\box102 553 | \temp@Answerbox=\box103 554 | \ExerciseDifficulty=\count306 555 | \QuestionDifficulty=\count307 556 | \subQuestionDifficulty=\count308 557 | \subsubQuestionDifficulty=\count309 558 | \ExePartDifficulty=\count310 559 | \@Answerbox=\box104 560 | \colonnesLevel=\count311 561 | \tempskipa=\skip113 562 | \tempskipb=\skip114 563 | \@savedmathindent=\skip115 564 | ) 565 | (/usr/share/texlive/texmf-dist/tex/latex/mdframed/mdframed.sty 566 | Package: mdframed 2013/07/01 1.9b: mdframed 567 | 568 | (/usr/share/texlive/texmf-dist/tex/latex/l3packages/xparse/xparse.sty 569 | (/usr/share/texlive/texmf-dist/tex/latex/l3kernel/expl3.sty 570 | Package: expl3 2022-01-21 L3 programming layer (loader) 571 | 572 | (/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def 573 | File: l3backend-pdftex.def 2022-01-12 L3 backend support: PDF output (pdfTeX) 574 | \l__color_backend_stack_int=\count312 575 | \l__pdf_internal_box=\box105 576 | )) 577 | Package: xparse 2022-01-12 L3 Experimental document command parser 578 | ) 579 | (/usr/share/texlive/texmf-dist/tex/latex/zref/zref-abspage.sty 580 | Package: zref-abspage 2020-07-03 v2.32 Module abspage for zref (HO) 581 | 582 | (/usr/share/texlive/texmf-dist/tex/latex/zref/zref-base.sty 583 | Package: zref-base 2020-07-03 v2.32 Module base for zref (HO) 584 | Package zref Info: New property list: main on input line 764. 585 | Package zref Info: New property: default on input line 765. 586 | Package zref Info: New property: page on input line 766. 587 | ) 588 | \c@abspage=\count313 589 | Package zref Info: New property: abspage on input line 66. 590 | ) 591 | (/usr/share/texlive/texmf-dist/tex/latex/needspace/needspace.sty 592 | Package: needspace 2010/09/12 v1.3d reserve vertical space 593 | ) 594 | \mdf@templength=\skip116 595 | \c@mdf@globalstyle@cnt=\count314 596 | \mdf@skipabove@length=\skip117 597 | \mdf@skipbelow@length=\skip118 598 | \mdf@leftmargin@length=\skip119 599 | \mdf@rightmargin@length=\skip120 600 | \mdf@innerleftmargin@length=\skip121 601 | \mdf@innerrightmargin@length=\skip122 602 | \mdf@innertopmargin@length=\skip123 603 | \mdf@innerbottommargin@length=\skip124 604 | \mdf@splittopskip@length=\skip125 605 | \mdf@splitbottomskip@length=\skip126 606 | \mdf@outermargin@length=\skip127 607 | \mdf@innermargin@length=\skip128 608 | \mdf@linewidth@length=\skip129 609 | \mdf@innerlinewidth@length=\skip130 610 | \mdf@middlelinewidth@length=\skip131 611 | \mdf@outerlinewidth@length=\skip132 612 | \mdf@roundcorner@length=\skip133 613 | \mdf@footenotedistance@length=\skip134 614 | \mdf@userdefinedwidth@length=\skip135 615 | \mdf@needspace@length=\skip136 616 | \mdf@frametitleaboveskip@length=\skip137 617 | \mdf@frametitlebelowskip@length=\skip138 618 | \mdf@frametitlerulewidth@length=\skip139 619 | \mdf@frametitleleftmargin@length=\skip140 620 | \mdf@frametitlerightmargin@length=\skip141 621 | \mdf@shadowsize@length=\skip142 622 | \mdf@extratopheight@length=\skip143 623 | \mdf@subtitleabovelinewidth@length=\skip144 624 | \mdf@subtitlebelowlinewidth@length=\skip145 625 | \mdf@subtitleaboveskip@length=\skip146 626 | \mdf@subtitlebelowskip@length=\skip147 627 | \mdf@subtitleinneraboveskip@length=\skip148 628 | \mdf@subtitleinnerbelowskip@length=\skip149 629 | \mdf@subsubtitleabovelinewidth@length=\skip150 630 | \mdf@subsubtitlebelowlinewidth@length=\skip151 631 | \mdf@subsubtitleaboveskip@length=\skip152 632 | \mdf@subsubtitlebelowskip@length=\skip153 633 | \mdf@subsubtitleinneraboveskip@length=\skip154 634 | \mdf@subsubtitleinnerbelowskip@length=\skip155 635 | 636 | (/usr/share/texlive/texmf-dist/tex/latex/mdframed/md-frame-0.mdf 637 | File: md-frame-0.mdf 2013/07/01\ 1.9b: md-frame-0 638 | ) 639 | \mdf@frametitlebox=\box106 640 | \mdf@footnotebox=\box107 641 | \mdf@splitbox@one=\box108 642 | \mdf@splitbox@two=\box109 643 | \mdf@splitbox@save=\box110 644 | \mdfsplitboxwidth=\skip156 645 | \mdfsplitboxtotalwidth=\skip157 646 | \mdfsplitboxheight=\skip158 647 | \mdfsplitboxdepth=\skip159 648 | \mdfsplitboxtotalheight=\skip160 649 | \mdfframetitleboxwidth=\skip161 650 | \mdfframetitleboxtotalwidth=\skip162 651 | \mdfframetitleboxheight=\skip163 652 | \mdfframetitleboxdepth=\skip164 653 | \mdfframetitleboxtotalheight=\skip165 654 | \mdffootnoteboxwidth=\skip166 655 | \mdffootnoteboxtotalwidth=\skip167 656 | \mdffootnoteboxheight=\skip168 657 | \mdffootnoteboxdepth=\skip169 658 | \mdffootnoteboxtotalheight=\skip170 659 | \mdftotallinewidth=\skip171 660 | \mdfboundingboxwidth=\skip172 661 | \mdfboundingboxtotalwidth=\skip173 662 | \mdfboundingboxheight=\skip174 663 | \mdfboundingboxdepth=\skip175 664 | \mdfboundingboxtotalheight=\skip176 665 | \mdf@freevspace@length=\skip177 666 | \mdf@horizontalwidthofbox@length=\skip178 667 | \mdf@verticalmarginwhole@length=\skip179 668 | \mdf@horizontalspaceofbox=\skip180 669 | \mdfsubtitleheight=\skip181 670 | \mdfsubsubtitleheight=\skip182 671 | \c@mdfcountframes=\count315 672 | 673 | ****** mdframed patching \endmdf@trivlist 674 | 675 | ****** -- success****** 676 | 677 | \mdf@envdepth=\count316 678 | \c@mdf@env@i=\count317 679 | \c@mdf@env@ii=\count318 680 | \c@mdf@zref@counter=\count319 681 | Package zref Info: New property: mdf@pagevalue on input line 895. 682 | ) 683 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty 684 | Package: amsmath 2021/10/15 v2.17l AMS math features 685 | \@mathmargin=\skip183 686 | 687 | For additional information on amsmath, use the `?' option. 688 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty 689 | Package: amstext 2021/08/26 v2.01 AMS text 690 | 691 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty 692 | File: amsgen.sty 1999/11/30 v2.0 generic functions 693 | \@emptytoks=\toks24 694 | \ex@=\dimen169 695 | )) 696 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty 697 | Package: amsbsy 1999/11/29 v1.2d Bold Symbols 698 | \pmbraise@=\dimen170 699 | ) 700 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty 701 | Package: amsopn 2021/08/26 v2.02 operator names 702 | ) 703 | \inf@bad=\count320 704 | LaTeX Info: Redefining \frac on input line 234. 705 | \uproot@=\count321 706 | \leftroot@=\count322 707 | LaTeX Info: Redefining \overline on input line 399. 708 | \classnum@=\count323 709 | \DOTSCASE@=\count324 710 | LaTeX Info: Redefining \ldots on input line 496. 711 | LaTeX Info: Redefining \dots on input line 499. 712 | LaTeX Info: Redefining \cdots on input line 620. 713 | \Mathstrutbox@=\box111 714 | \strutbox@=\box112 715 | \big@size=\dimen171 716 | LaTeX Font Info: Redeclaring font encoding OML on input line 743. 717 | LaTeX Font Info: Redeclaring font encoding OMS on input line 744. 718 | \macc@depth=\count325 719 | \c@MaxMatrixCols=\count326 720 | \dotsspace@=\muskip17 721 | \c@parentequation=\count327 722 | \dspbrk@lvl=\count328 723 | \tag@help=\toks25 724 | \row@=\count329 725 | \column@=\count330 726 | \maxfields@=\count331 727 | \andhelp@=\toks26 728 | \eqnshift@=\dimen172 729 | \alignsep@=\dimen173 730 | \tagshift@=\dimen174 731 | \tagwidth@=\dimen175 732 | \totwidth@=\dimen176 733 | \lineht@=\dimen177 734 | \@envbody=\toks27 735 | \multlinegap=\skip184 736 | \multlinetaggap=\skip185 737 | \mathdisplay@stack=\toks28 738 | LaTeX Info: Redefining \[ on input line 2938. 739 | LaTeX Info: Redefining \] on input line 2939. 740 | ) 741 | (/usr/share/texlive/texmf-dist/tex/latex/appendix/appendix.sty 742 | Package: appendix 2020/02/08 v1.2c extra appendix facilities 743 | \c@@pps=\count332 744 | \c@@ppsavesec=\count333 745 | \c@@ppsaveapp=\count334 746 | ) 747 | (/usr/share/texlive/texmf-dist/tex/generic/soul/soul.sty 748 | Package: soul 2003/11/17 v2.4 letterspacing/underlining (mf) 749 | \SOUL@word=\toks29 750 | \SOUL@lasttoken=\toks30 751 | \SOUL@cmds=\toks31 752 | \SOUL@buffer=\toks32 753 | \SOUL@token=\toks33 754 | \SOUL@spaceskip=\skip186 755 | \SOUL@ttwidth=\dimen178 756 | \SOUL@uldp=\dimen179 757 | \SOUL@ulht=\dimen180 758 | ) 759 | (/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty 760 | Package: graphicx 2021/09/16 v1.2d Enhanced LaTeX Graphics (DPC,SPQR) 761 | 762 | (/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty 763 | Package: graphics 2021/03/04 v1.4d Standard LaTeX Graphics (DPC,SPQR) 764 | 765 | (/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty 766 | Package: trig 2021/08/11 v1.11 sin cos tan (DPC) 767 | ) 768 | (/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg 769 | File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration 770 | ) 771 | Package graphics Info: Driver file: pdftex.def on input line 107. 772 | ) 773 | \Gin@req@height=\dimen181 774 | \Gin@req@width=\dimen182 775 | ) 776 | (/usr/share/texlive/texmf-dist/tex/latex/base/makeidx.sty 777 | Package: makeidx 2021/10/04 v1.0m Standard LaTeX package 778 | ) 779 | \@indexfile=\write3 780 | \openout3 = `python.idx'. 781 | 782 | 783 | Writing index file python.idx 784 | (./ccicons.sty 785 | Package: ccicons 2017/10/30 v1.6 LaTeX support for Creative Commons icons 786 | ) (/usr/share/texlive/texmf-dist/tex/latex/csquotes/csquotes.sty 787 | Package: csquotes 2021-02-22 v5.2l context-sensitive quotations (JAW) 788 | \csq@reset=\count335 789 | \csq@gtype=\count336 790 | \csq@glevel=\count337 791 | \csq@qlevel=\count338 792 | \csq@maxlvl=\count339 793 | \csq@tshold=\count340 794 | \csq@ltx@everypar=\toks34 795 | 796 | (/usr/share/texlive/texmf-dist/tex/latex/csquotes/csquotes.def 797 | File: csquotes.def 2021-02-22 v5.2l csquotes generic definitions (JAW) 798 | ) 799 | Package csquotes Info: Trying to load configuration file 'csquotes.cfg'... 800 | Package csquotes Info: ... configuration file loaded successfully. 801 | 802 | (/usr/share/texlive/texmf-dist/tex/latex/csquotes/csquotes.cfg 803 | File: csquotes.cfg 804 | )) (./python.aux 805 | (./pengantar.aux) (./pendahuluan.aux) (./advanced.aux) (./tricks.aux)) 806 | \openout1 = `python.aux'. 807 | 808 | LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 31. 809 | LaTeX Font Info: ... okay on input line 31. 810 | LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 31. 811 | LaTeX Font Info: ... okay on input line 31. 812 | LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 31. 813 | LaTeX Font Info: ... okay on input line 31. 814 | LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 31. 815 | LaTeX Font Info: ... okay on input line 31. 816 | LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 31. 817 | LaTeX Font Info: ... okay on input line 31. 818 | LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 31. 819 | LaTeX Font Info: ... okay on input line 31. 820 | LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 31. 821 | LaTeX Font Info: ... okay on input line 31. 822 | LaTeX Font Info: Checking defaults for PD1/pdf/m/n on input line 31. 823 | LaTeX Font Info: ... okay on input line 31. 824 | LaTeX Font Info: Checking defaults for PU/pdf/m/n on input line 31. 825 | LaTeX Font Info: ... okay on input line 31. 826 | Package hyperref Info: Link coloring OFF on input line 31. 827 | 828 | (/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty 829 | Package: nameref 2021-04-02 v2.47 Cross-referencing by name of section 830 | 831 | (/usr/share/texlive/texmf-dist/tex/latex/refcount/refcount.sty 832 | Package: refcount 2019/12/15 v3.6 Data extraction from label references (HO) 833 | ) 834 | (/usr/share/texlive/texmf-dist/tex/generic/gettitlestring/gettitlestring.sty 835 | Package: gettitlestring 2019/12/15 v1.6 Cleanup title references (HO) 836 | ) 837 | \c@section@level=\count341 838 | ) 839 | LaTeX Info: Redefining \ref on input line 31. 840 | LaTeX Info: Redefining \pageref on input line 31. 841 | LaTeX Info: Redefining \nameref on input line 31. 842 | 843 | (./python.out) (./python.out) 844 | \@outlinefile=\write4 845 | \openout4 = `python.out'. 846 | 847 | 848 | *geometry* driver: auto-detecting 849 | *geometry* detected driver: pdftex 850 | *geometry* verbose mode - [ preamble ] result: 851 | * driver: pdftex 852 | * paper: letterpaper 853 | * layout: 854 | * layoutoffset:(h,v)=(0.0pt,0.0pt) 855 | * modes: twoside asymmetric 856 | * h-part:(L,W,R)=(72.26999pt, 312.0pt, 230.02501pt) 857 | * v-part:(T,H,B)=(72.26999pt, 616.0pt, 106.7pt) 858 | * \paperwidth=614.295pt 859 | * \paperheight=794.96999pt 860 | * \textwidth=312.0pt 861 | * \textheight=616.0pt 862 | * \oddsidemargin=0.0pt 863 | * \evensidemargin=0.0pt 864 | * \topmargin=-42.0pt 865 | * \headheight=14.0pt 866 | * \headsep=28.0pt 867 | * \topskip=10.0pt 868 | * \footskip=25.29494pt 869 | * \marginparwidth=144.0pt 870 | * \marginparsep=24.0pt 871 | * \columnsep=10.0pt 872 | * \skip\footins=9.0pt plus 4.0pt minus 2.0pt 873 | * \hoffset=0.0pt 874 | * \voffset=0.0pt 875 | * \mag=1000 876 | * \@twocolumnfalse 877 | * \@twosidetrue 878 | * \@mparswitchfalse 879 | * \@reversemarginfalse 880 | * (1in=72.27pt=25.4mm, 1cm=28.453pt) 881 | 882 | \langwohyphens=\language3 883 | (/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii 884 | [Loading MPS to PDF converter (version 2006.09.02).] 885 | \scratchcounter=\count342 886 | \scratchdimen=\dimen183 887 | \scratchbox=\box113 888 | \nofMPsegments=\count343 889 | \nofMParguments=\count344 890 | \everyMPshowfont=\toks35 891 | \MPscratchCnt=\count345 892 | \MPscratchDim=\dimen184 893 | \MPnumerator=\count346 894 | \makeMPintoPDFobject=\count347 895 | \everyMPtoPDFconversion=\toks36 896 | ) (/usr/share/texlive/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty 897 | Package: epstopdf-base 2020-01-24 v2.11 Base part for package epstopdf 898 | Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4 899 | 85. 900 | 901 | (/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg 902 | File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv 903 | e 904 | )) 905 | LaTeX Font Info: Trying to load font information for T1+phv on input line 38 906 | . 907 | 908 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/t1phv.fd 909 | File: t1phv.fd 2020/03/25 scalable font definitions for T1/phv. 910 | ) 911 | LaTeX Font Info: Font shape `T1/phv/m/n' will be 912 | (Font) scaled to size 8.99994pt on input line 38. 913 | LaTeX Font Info: Font shape `T1/phv/m/n' will be 914 | (Font) scaled to size 16.19989pt on input line 38. 915 | LaTeX Font Info: Font shape `T1/phv/m/n' will be 916 | (Font) scaled to size 32.39978pt on input line 38. 917 | 918 | Overfull \hbox (29.85883pt too wide) in paragraph at lines 38--38 919 | []\T1/phv/m/n/36/200ls PEMROGRAMAN PYTHON[] 920 | [] 921 | 922 | LaTeX Font Info: Font shape `T1/phv/m/n' will be 923 | (Font) scaled to size 12.59991pt on input line 38. 924 | [1.1 925 | 926 | 927 | {/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] [2.2 928 | 929 | 930 | ] (./python.toc) 931 | \tf@toc=\write5 932 | \openout5 = `python.toc'. 933 | 934 | 935 | [3.3] 936 | \openout2 = `pengantar.aux'. 937 | 938 | (./pengantar.tex [4.4 939 | 940 | 941 | ]) [5.5] 942 | \openout2 = `pendahuluan.aux'. 943 | 944 | (./pendahuluan.tex [6.6 945 | 946 | 947 | 948 | 949 | ] 950 | Chapter 1. 951 | [7.7] 952 | 953 | File: graphics/google-colab.jpg Graphic file (type jpg) 954 | 955 | Package pdftex.def Info: graphics/google-colab.jpg used on input line 71. 956 | (pdftex.def) Requested size: 312.00565pt x 134.9106pt. 957 | 958 | Underfull \hbox (badness 10000) in paragraph at lines 71--73 959 | 960 | [] 961 | 962 | [8.8] 963 | LaTeX Font Info: Trying to load font information for T1+cmtt on input line 9 964 | 5. 965 | (/usr/share/texlive/texmf-dist/tex/latex/base/t1cmtt.fd 966 | File: t1cmtt.fd 2019/12/16 v2.5j Standard LaTeX font definitions 967 | ) 968 | Overfull \hbox (55.41028pt too wide) in paragraph at lines 99--99 969 | []\T1/cmtt/m/n/10 Type "help", "copyright", "credits" or "license" for more inf 970 | ormation.[] 971 | [] 972 | 973 | [9.9 <./graphics/google-colab.jpg>] 974 | Overfull \hbox (55.41028pt too wide) in paragraph at lines 125--125 975 | []\T1/cmtt/m/n/10 Type "help", "copyright", "credits" or "license" for more inf 976 | ormation.[] 977 | [] 978 | 979 | 980 | Overfull \hbox (3.95981pt too wide) in paragraph at lines 135--141 981 | \T1/pplj/m/n/10 berikan spasi di de-pan per-in-tah ``print(i)''. Se-harus-nya k 982 | ita melakukan 983 | [] 984 | 985 | 986 | Overfull \hbox (55.41028pt too wide) in paragraph at lines 146--146 987 | []\T1/cmtt/m/n/10 Type "help", "copyright", "credits" or "license" for more inf 988 | ormation.[] 989 | [] 990 | 991 | [10.10] 992 | Overfull \hbox (5.39986pt too wide) in paragraph at lines 207--210 993 | []\T1/pplj/m/n/10 Pada contoh-contoh di atas hasil print dic-etak ke bawah. Bag 994 | aimana 995 | [] 996 | 997 | [11.11] 998 | Overfull \hbox (17.21985pt too wide) in paragraph at lines 251--257 999 | []\T1/pplj/m/n/10 Variabel di dalam Python lang-sung da-pat di-gu-nakan tanpa m 1000 | elakukan 1001 | [] 1002 | 1003 | LaTeX Font Info: Trying to load font information for OT1+pplx on input line 1004 | 262. 1005 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/ot1pplx.fd 1006 | File: ot1pplx.fd 2004/09/06 font definitions for OT1/pplx. 1007 | ) 1008 | LaTeX Font Info: Trying to load font information for OML+zplm on input line 1009 | 262. 1010 | 1011 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/omlzplm.fd 1012 | File: omlzplm.fd 2002/09/08 Fontinst v1.914 font definitions for OML/zplm. 1013 | ) 1014 | LaTeX Font Info: Trying to load font information for OMS+zplm on input line 1015 | 262. 1016 | 1017 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/omszplm.fd 1018 | File: omszplm.fd 2002/09/08 Fontinst v1.914 font definitions for OMS/zplm. 1019 | ) 1020 | LaTeX Font Info: Trying to load font information for OMX+zplm on input line 1021 | 262. 1022 | 1023 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/omxzplm.fd 1024 | File: omxzplm.fd 2002/09/08 Fontinst v1.914 font definitions for OMX/zplm. 1025 | ) 1026 | LaTeX Font Info: Trying to load font information for OT1+zplm on input line 1027 | 262. 1028 | 1029 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/ot1zplm.fd 1030 | File: ot1zplm.fd 2002/09/08 Fontinst v1.914 font definitions for OT1/zplm. 1031 | ) [12.12] [13.13] 1032 | [14.14] 1033 | Overfull \hbox (8.28984pt too wide) in paragraph at lines 386--389 1034 | []\T1/pplj/m/n/10 Ada juga al-go-ritme yang lama per-hi-tun-gan-nya berband-ing 1035 | kuadratis 1036 | [] 1037 | 1038 | [15.15] [16.16] [17.17] 1039 | Overfull \hbox (50.16156pt too wide) in paragraph at lines 543--543 1040 | []\T1/cmtt/m/n/10 people = ["budi", "cecep", "rudi", "ani", "BUDI", "rahardjo", 1041 | "zoro"][] 1042 | [] 1043 | 1044 | 1045 | Overfull \hbox (2.9231pt too wide) in paragraph at lines 546--546 1046 | []\T1/cmtt/m/n/10 ['budi', 'cecep', 'rudi', 'ani', 'BUDI', 'rahardjo', 'zoro'][ 1047 | ] 1048 | [] 1049 | 1050 | 1051 | Overfull \hbox (2.9231pt too wide) in paragraph at lines 557--557 1052 | []\T1/cmtt/m/n/10 ['zoro', 'rudi', 'rahardjo', 'cecep', 'budi', 'ani', 'BUDI'][ 1053 | ] 1054 | [] 1055 | 1056 | 1057 | Overfull \hbox (2.9231pt too wide) in paragraph at lines 570--570 1058 | []\T1/cmtt/m/n/10 ['budi', 'cecep', 'rudi', 'ani', 'budi', 'rahardjo', 'zoro'][ 1059 | ] 1060 | [] 1061 | 1062 | 1063 | Overfull \hbox (2.9231pt too wide) in paragraph at lines 581--581 1064 | []\T1/cmtt/m/n/10 ['Budi', 'Cecep', 'Rudi', 'Ani', 'Budi', 'Rahardjo', 'Zoro'][ 1065 | ] 1066 | [] 1067 | 1068 | [18.18] [19.19] [20.20] 1069 | Overfull \hbox (8.17181pt too wide) in paragraph at lines 698--698 1070 | []\T1/cmtt/m/n/10 kalimat = raw_input("Masukkan kalimat yang cukup panjang.\n") 1071 | [] 1072 | [] 1073 | 1074 | [21.21] 1075 | 1076 | LaTeX Warning: Marginpar on page 22 moved. 1077 | 1078 | 1079 | Underfull \hbox (badness 2846) in paragraph at lines 773--773 1080 | $[]$\T1/pplj/m/n/8 Kode ini ada di 1081 | [] 1082 | 1083 | 1084 | LaTeX Warning: Marginpar on page 22 moved. 1085 | 1086 | 1087 | Overfull \hbox (8.17181pt too wide) in paragraph at lines 778--778 1088 | []\T1/cmtt/m/n/10 # kata orang jangan di-slurp tapi dibaca perbaris seperti ini 1089 | [] 1090 | [] 1091 | 1092 | [22.22] 1093 | 1094 | LaTeX Warning: Marginpar on page 23 moved. 1095 | 1096 | 1097 | Overfull \hbox (3.39989pt too wide) in paragraph at lines 823--829 1098 | \T1/pplj/m/n/10 ``.bashrc'' pada \T1/pplj/m/it/10 home di-rec-tory \T1/pplj/m/n 1099 | /10 Anda (atau pada berkas ``.bash_aliases''). 1100 | [] 1101 | 1102 | ) [23.23] 1103 | \openout2 = `advanced.aux'. 1104 | 1105 | (./advanced.tex [24.24 1106 | 1107 | 1108 | 1109 | 1110 | ] 1111 | Chapter 2. 1112 | [25.25] 1113 | 1114 | LaTeX Warning: Characters dropped after `\end{verbatim}' on input line 39. 1115 | 1116 | [26.26] 1117 | Overfull \hbox (8.17181pt too wide) in paragraph at lines 156--156 1118 | []\T1/cmtt/m/n/10 [98 84 72 57 61 98 60 96 75 86 95 81 62 77 67 52 73 96 95 71] 1119 | [] 1120 | [] 1121 | 1122 | [27.27] [28.28] 1123 | 1124 | File: graphics/matplotlib-contoh1.png Graphic file (type png) 1125 | 1126 | Package pdftex.def Info: graphics/matplotlib-contoh1.png used on input line 22 1127 | 0. 1128 | (pdftex.def) Requested size: 312.01318pt x 237.31389pt. 1129 | 1130 | Overfull \hbox (6.81317pt too wide) in paragraph at lines 220--223 1131 | [][] 1132 | [] 1133 | 1134 | 1135 | Underfull \hbox (badness 10000) in paragraph at lines 220--223 1136 | 1137 | [] 1138 | 1139 | 1140 | File: graphics/matplotlib-contoh2.png Graphic file (type png) 1141 | 1142 | Package pdftex.def Info: graphics/matplotlib-contoh2.png used on input line 24 1143 | 8. 1144 | (pdftex.def) Requested size: 312.01318pt x 237.31389pt. 1145 | 1146 | Overfull \hbox (6.81317pt too wide) in paragraph at lines 248--251 1147 | [][] 1148 | [] 1149 | 1150 | 1151 | Underfull \hbox (badness 10000) in paragraph at lines 248--251 1152 | 1153 | [] 1154 | 1155 | [29.29 <./graphics/matplotlib-contoh1.png>] 1156 | 1157 | File: graphics/matplotlib-gausian.png Graphic file (type png) 1158 | 1159 | Package pdftex.def Info: graphics/matplotlib-gausian.png used on input line 27 1160 | 4. 1161 | (pdftex.def) Requested size: 311.99846pt x 239.828pt. 1162 | 1163 | Overfull \hbox (6.79845pt too wide) in paragraph at lines 274--277 1164 | [][] 1165 | [] 1166 | 1167 | 1168 | Underfull \hbox (badness 10000) in paragraph at lines 274--277 1169 | 1170 | [] 1171 | 1172 | [30.30 <./graphics/matplotlib-contoh2.png>] 1173 | 1174 | LaTeX Warning: Marginpar on page 31 moved. 1175 | 1176 | [31.31 <./graphics/matplotlib-gausian.png>] 1177 | 1178 | File: graphics/random-data.png Graphic file (type png) 1179 | 1180 | Package pdftex.def Info: graphics/random-data.png used on input line 322. 1181 | (pdftex.def) Requested size: 312.01648pt x 234.01236pt. 1182 | 1183 | Overfull \hbox (6.81647pt too wide) in paragraph at lines 322--325 1184 | [][] 1185 | [] 1186 | 1187 | 1188 | Underfull \hbox (badness 10000) in paragraph at lines 322--325 1189 | 1190 | [] 1191 | 1192 | 1193 | Overfull \hbox (16.51976pt too wide) in paragraph at lines 334--344 1194 | \T1/pplj/m/n/10 nakan Numpy seperti con-toh di bawah ini. Berkas ``linear-regre 1195 | ssion.csv'' 1196 | [] 1197 | 1198 | 1199 | Overfull \hbox (0.89948pt too wide) in paragraph at lines 334--344 1200 | \T1/pplj/m/n/10 dis-im-pan pada di-rek-tori di-mana kode ini di-jalankan. Vari- 1201 | abel $\OML/zplm/m/it/10 x[]point$ 1202 | [] 1203 | 1204 | 1205 | Overfull \hbox (212.87183pt too wide) in paragraph at lines 346--346 1206 | []\T1/cmtt/m/n/10 np.savetxt("linear-regression.csv", np.column_stack([x_point, 1207 | y_point]), fmt='%.5f', delimiter=', ')[] 1208 | [] 1209 | 1210 | [32.32 <./graphics/random-data.png>] 1211 | Overfull \hbox (44.91284pt too wide) in paragraph at lines 359--359 1212 | []\T1/cmtt/m/n/10 # do not forget to install scipy first: python3 -m pip instal 1213 | l scipy[] 1214 | [] 1215 | 1216 | 1217 | Overfull \hbox (13.42053pt too wide) in paragraph at lines 362--362 1218 | []\T1/cmtt/m/n/10 my_csv = np.genfromtxt('linear-regression.csv', delimiter=',' 1219 | )[] 1220 | [] 1221 | 1222 | 1223 | Overfull \hbox (34.4154pt too wide) in paragraph at lines 364--364 1224 | []\T1/cmtt/m/n/10 gradient,intercept,r_value,p_value,std_err=stats.linregress(x 1225 | p,yp)[] 1226 | [] 1227 | 1228 | [33.33] 1229 | Overfull \hbox (176.1308pt too wide) in paragraph at lines 406--406 1230 | [] \T1/cmtt/m/n/10 np.savetxt("cluster.csv", np.column_stack([x_point, y_poin 1231 | t]), fmt='%.5f', delimiter=', ')[] 1232 | [] 1233 | 1234 | 1235 | File: graphics/cluster-create.jpg Graphic file (type jpg) 1236 | 1237 | Package pdftex.def Info: graphics/cluster-create.jpg used on input line 419. 1238 | (pdftex.def) Requested size: 311.99518pt x 269.69073pt. 1239 | 1240 | Overfull \hbox (6.79517pt too wide) in paragraph at lines 419--422 1241 | [][] 1242 | [] 1243 | 1244 | 1245 | Underfull \hbox (badness 10000) in paragraph at lines 419--422 1246 | 1247 | [] 1248 | 1249 | [34.34 <./graphics/cluster-create.jpg>] 1250 | 1251 | LaTeX Warning: Marginpar on page 35 moved. 1252 | 1253 | [35.35] 1254 | 1255 | File: graphics/3cluster.jpg Graphic file (type jpg) 1256 | 1257 | Package pdftex.def Info: graphics/3cluster.jpg used on input line 515. 1258 | (pdftex.def) Requested size: 311.99518pt x 269.69073pt. 1259 | 1260 | Overfull \hbox (6.79517pt too wide) in paragraph at lines 515--518 1261 | [][] 1262 | [] 1263 | 1264 | 1265 | Underfull \hbox (badness 10000) in paragraph at lines 515--518 1266 | 1267 | [] 1268 | 1269 | 1270 | Overfull \hbox (81.65387pt too wide) in paragraph at lines 531--531 1271 | []\T1/cmtt/m/n/10 plt.scatter(df['x'],df['y'], c=kmeans.labels_.astype(float),s 1272 | =50,alpha=0.5)[] 1273 | [] 1274 | 1275 | 1276 | File: graphics/3cluster-kmeans.jpg Graphic file (type jpg) 1277 | 1278 | Package pdftex.def Info: graphics/3cluster-kmeans.jpg used on input line 549. 1279 | (pdftex.def) Requested size: 311.99518pt x 269.69073pt. 1280 | 1281 | Overfull \hbox (6.79517pt too wide) in paragraph at lines 549--552 1282 | [][] 1283 | [] 1284 | 1285 | 1286 | Underfull \hbox (badness 10000) in paragraph at lines 549--552 1287 | 1288 | [] 1289 | 1290 | [36.36] (./opencv.tex [37.37 <./graphics/3cluster.jpg>] 1291 | Overfull \hbox (6.19981pt too wide) in paragraph at lines 28--33 1292 | []\T1/pplj/m/n/10 Program akan menampilkan gam-bar se-belum dan sesu-dah dipros 1293 | es, 1294 | [] 1295 | 1296 | 1297 | File: graphics/br-pixel.png Graphic file (type png) 1298 | 1299 | Package pdftex.def Info: graphics/br-pixel.png used on input line 35. 1300 | (pdftex.def) Requested size: 312.00104pt x 245.70082pt. 1301 | 1302 | Underfull \hbox (badness 10000) in paragraph at lines 35--37 1303 | 1304 | [] 1305 | 1306 | 1307 | File: graphics/br-pixel-grey.png Graphic file (type png) 1308 | 1309 | Package pdftex.def Info: graphics/br-pixel-grey.png used on input line 40. 1310 | (pdftex.def) Requested size: 311.99002pt x 245.69214pt. 1311 | 1312 | Underfull \hbox (badness 10000) in paragraph at lines 40--42 1313 | [][] 1314 | [] 1315 | 1316 | 1317 | Underfull \hbox (badness 10000) in paragraph at lines 40--42 1318 | 1319 | [] 1320 | 1321 | ) [38.38 <./graphics/3cluster-kmeans.jpg>] [39.39 <./graphics/br-pixel.png> <./ 1322 | graphics/br-pixel-grey.png (PNG copy)>] 1323 | Overfull \hbox (34.4154pt too wide) in paragraph at lines 583--583 1324 | []\T1/cmtt/m/n/10 375a6c46228994656932f4aa17d9ae50f21da75a31ff17f8517c255c06cba 1325 | 809 -[] 1326 | [] 1327 | 1328 | 1329 | Overfull \hbox (81.65387pt too wide) in paragraph at lines 588--588 1330 | []\T1/cmtt/m/n/10 375a6c46228994656932f4aa17d9ae50f21da75a31ff17f8517c255c06cba 1331 | 809 pesan1.txt[] 1332 | [] 1333 | 1334 | 1335 | Overfull \hbox (81.65387pt too wide) in paragraph at lines 593--593 1336 | []\T1/cmtt/m/n/10 5901bccc6a0556fac2b4a164ef831a7ed4ceddeb60c6ddde1162f5a40b9d2 1337 | 917 pesan2.txt[] 1338 | [] 1339 | 1340 | 1341 | Overfull \hbox (52.74152pt too wide) in paragraph at lines 609--609 1342 | $[]$\T1/pplj/m/n/8 https://rahard.wordpress.com/2018/03/10/berburu- 1343 | [] 1344 | 1345 | ) 1346 | 1347 | LaTeX Warning: Marginpar on page 40 moved. 1348 | 1349 | [40.40] 1350 | \openout2 = `tricks.aux'. 1351 | 1352 | (./tricks.tex 1353 | Chapter 3. 1354 | [41.41 1355 | 1356 | 1357 | 1358 | 1359 | ] 1360 | Overfull \hbox (19.11987pt too wide) in paragraph at lines 57--60 1361 | []\T1/pplj/m/n/10 Berikut ini adalah con-toh kode yang lazim dite-mui, yaitu me 1362 | nanamkan 1363 | [] 1364 | 1365 | [42.42] 1366 | Overfull \hbox (2.9231pt too wide) in paragraph at lines 134--134 1367 | []\T1/cmtt/m/n/10 a_file = open("budi-unicode.txt", "r", encoding='utf-16-le')[ 1368 | ] 1369 | [] 1370 | 1371 | 1372 | Overfull \hbox (8.17181pt too wide) in paragraph at lines 135--135 1373 | []\T1/cmtt/m/n/10 #a_file = open("budi-unicode.txt", "r", encoding='utf-16-be') 1374 | [] 1375 | [] 1376 | 1377 | [43.43] 1378 | 1379 | LaTeX Warning: Marginpar on page 44 moved. 1380 | 1381 | ) [44.44] (./python.bbl 1382 | Chapter 4. 1383 | pdfTeX warning (ext4): destination with the same identifier (name{cite.tensorfl 1384 | owstarted}) has been already used, duplicate ignored 1385 | 1386 | \relax 1387 | l.3 \bibitem{tensorflowstarted} 1388 | ) 1389 | (/usr/share/texlive/texmf-dist/tex/generic/stringenc/se-pdfdoc.def 1390 | File: se-pdfdoc.def 2019/11/29 v1.12 stringenc: PDFDocEncoding 1391 | ) 1392 | (/usr/share/texlive/texmf-dist/tex/generic/stringenc/se-utf8.def 1393 | File: se-utf8.def 2019/11/29 v1.12 stringenc: UTF-8 1394 | ) [45.45 1395 | 1396 | 1397 | 1398 | ] 1399 | (./python.aux (./pengantar.aux) (./pendahuluan.aux) (./advanced.aux) 1400 | (./tricks.aux)) 1401 | Package rerunfilecheck Info: File `python.out' has not changed. 1402 | (rerunfilecheck) Checksum: 8394D4A44CF09F6FA0569F9DACBC322D;3190. 1403 | ) 1404 | Here is how much of TeX's memory you used: 1405 | 17423 strings out of 480247 1406 | 284762 string characters out of 5896150 1407 | 643585 words of memory out of 5000000 1408 | 34839 multiletter control sequences out of 15000+600000 1409 | 546073 words of font info for 124 fonts, out of 8000000 for 9000 1410 | 14 hyphenation exceptions out of 8191 1411 | 94i,12n,94p,843b,539s stack positions out of 5000i,500n,10000p,200000b,80000s 1412 | {/usr/share/texlive/texmf-dist/fonts/enc/dvips/base/8r.enc} 1422 | Output written on python.pdf (45 pages, 2784832 bytes). 1423 | PDF statistics: 1424 | 494 PDF objects out of 1000 (max. 8388607) 1425 | 316 compressed objects within 4 object streams 1426 | 75 named destinations out of 1000 (max. 500000) 1427 | 2815 words of extra memory for PDF output out of 10000 (max. 10000000) 1428 | 1429 | -------------------------------------------------------------------------------- /python.out: -------------------------------------------------------------------------------- 1 | \BOOKMARK [0][-]{chapter.1}{\376\377\000P\000e\000n\000d\000a\000h\000u\000l\000u\000a\000n}{}% 1 2 | \BOOKMARK [1][-]{section.1.1}{\376\377\000I\000n\000s\000t\000a\000l\000a\000s\000i}{chapter.1}% 2 3 | \BOOKMARK [1][-]{section.1.2}{\376\377\000P\000y\000t\000h\000o\000n\000\040\000T\000a\000n\000p\000a\000\040\000I\000n\000s\000t\000a\000l\000a\000s\000i\000\040\000-\000\040\000G\000o\000o\000g\000l\000e\000\040\000C\000o\000l\000a\000b}{chapter.1}% 3 4 | \BOOKMARK [1][-]{section.1.3}{\376\377\000M\000e\000m\000u\000l\000a\000i}{chapter.1}% 4 5 | \BOOKMARK [1][-]{section.1.4}{\376\377\000S\000h\000e\000l\000l\000\040\000a\000t\000a\000u\000\040\000I\000D\000E}{chapter.1}% 5 6 | \BOOKMARK [1][-]{section.1.5}{\376\377\000B\000a\000h\000a\000s\000a\000\040\000P\000y\000t\000h\000o\000n}{chapter.1}% 6 7 | \BOOKMARK [1][-]{section.1.6}{\376\377\000K\000o\000m\000p\000l\000e\000k\000s\000i\000t\000a\000s}{chapter.1}% 7 8 | \BOOKMARK [1][-]{section.1.7}{\376\377\000L\000i\000s\000t}{chapter.1}% 8 9 | \BOOKMARK [1][-]{section.1.8}{\376\377\000I\000n\000p\000u\000t}{chapter.1}% 9 10 | \BOOKMARK [1][-]{section.1.9}{\376\377\000P\000e\000n\000c\000a\000b\000a\000n\000g\000a\000n\000\040\000-\000\040\000B\000r\000a\000n\000c\000h\000i\000n\000g}{chapter.1}% 10 11 | \BOOKMARK [1][-]{section.1.10}{\376\377\000P\000e\000m\000r\000o\000s\000e\000s\000a\000n\000\040\000T\000e\000k\000s}{chapter.1}% 11 12 | \BOOKMARK [1][-]{section.1.11}{\376\377\000M\000e\000m\000b\000a\000c\000a\000\040\000B\000e\000r\000k\000a\000s\000:\000\040\000t\000o\000p\000i\000c\000\040\000g\000e\000n\000e\000r\000a\000t\000o\000r}{chapter.1}% 12 13 | \BOOKMARK [1][-]{section.1.12}{\376\377\000P\000y\000t\000h\000o\000n\0003}{chapter.1}% 13 14 | \BOOKMARK [0][-]{chapter.2}{\376\377\000K\000o\000d\000i\000n\000g\000\040\000T\000i\000n\000g\000k\000a\000t\000\040\000M\000e\000d\000i\000u\000m}{}% 14 15 | \BOOKMARK [1][-]{section.2.1}{\376\377\000A\000r\000g\000u\000m\000e\000n\000\040\000C\000L\000I}{chapter.2}% 15 16 | \BOOKMARK [1][-]{section.2.2}{\376\377\000N\000u\000m\000p\000y}{chapter.2}% 16 17 | \BOOKMARK [1][-]{section.2.3}{\376\377\000M\000a\000t\000l\000p\000l\000o\000t\000l\000i\000b}{chapter.2}% 17 18 | \BOOKMARK [1][-]{section.2.4}{\376\377\000P\000a\000n\000d\000a\000s}{chapter.2}% 18 19 | \BOOKMARK [1][-]{section.2.5}{\376\377\000O\000p\000e\000n\000C\000V}{chapter.2}% 19 20 | \BOOKMARK [1][-]{section.2.6}{\376\377\000K\000r\000i\000p\000t\000o\000g\000r\000a\000f\000i}{chapter.2}% 20 21 | \BOOKMARK [0][-]{chapter.3}{\376\377\000T\000r\000i\000k\000s}{}% 21 22 | \BOOKMARK [1][-]{section.3.1}{\376\377\000S\000e\000r\000v\000e\000r\000\040\000W\000e\000b}{chapter.3}% 22 23 | \BOOKMARK [1][-]{section.3.2}{\376\377\000M\000e\000m\000b\000a\000c\000a\000\040\000B\000e\000r\000k\000a\000s\000\040\000K\000o\000n\000f\000u\000g\000u\000r\000a\000s\000i\000\040\000c\000o\000n\000f\000i\000g\000.\000i\000n\000i}{chapter.3}% 23 24 | \BOOKMARK [1][-]{section.3.3}{\376\377\000M\000e\000n\000u\000l\000i\000s\000\040\000b\000e\000r\000k\000a\000s\000\040\000d\000a\000l\000a\000m\000\040\000f\000o\000r\000m\000a\000t\000\040\000U\000n\000i\000c\000o\000d\000e}{chapter.3}% 24 25 | \BOOKMARK [0][-]{chapter.4}{\376\377\000B\000i\000b\000l\000i\000o\000g\000r\000a\000p\000h\000y}{}% 25 26 | -------------------------------------------------------------------------------- /python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rahard/buku-python/21a66ba6ec5e8ac6eb117c1ca2fca887435db57d/python.pdf -------------------------------------------------------------------------------- /python.tex: -------------------------------------------------------------------------------- 1 | %%\documentclass{tufte-book} 2 | 3 | \documentclass{tufte-book} 4 | \usepackage[ 5 | type={CC}, 6 | modifier={by-nc-sa}, 7 | version={3.0}, 8 | ]{doclicense} 9 | \usepackage[lastexercise]{exercise} 10 | \usepackage{xcolor} 11 | \usepackage{mdframed} 12 | \usepackage{amsmath} 13 | \usepackage[toc,page]{appendix} 14 | \usepackage{soul} 15 | 16 | % supaya subsection bernomor 17 | \setcounter{secnumdepth}{2} 18 | 19 | 20 | 21 | \title{Pemrograman Python} 22 | \author{Budi Rahardjo} 23 | 24 | \usepackage{graphicx} % Needed to insert images into the document 25 | \graphicspath{{graphics/}} % Sets the default location of pictures 26 | \setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio} % 27 | 28 | \usepackage{makeidx} 29 | \makeindex 30 | 31 | \begin{document} 32 | 33 | 34 | %%\frontmatter 35 | %\fbox{\includegraphics[width=1.0\linewidth]{graphics/BR-starting-up.png}} 36 | %\includegraphics[width=1.0\linewidth]{graphics/BR-starting-up.png} 37 | 38 | \maketitle 39 | 40 | \tableofcontents 41 | 42 | \include{pengantar} 43 | \include{pendahuluan} 44 | \include{advanced} 45 | \include{tricks} 46 | 47 | \bibliography{referensi} 48 | 49 | %\bibliographystyle{plainnat} 50 | %\bibliographystyle{alpha} 51 | \bibliographystyle{plain} 52 | 53 | \end{document} 54 | -------------------------------------------------------------------------------- /python.toc: -------------------------------------------------------------------------------- 1 | \contentsline {chapter}{\numberline {1}Pendahuluan}{7}{chapter.1}% 2 | \contentsline {section}{\numberline {1.1}Instalasi}{8}{section.1.1}% 3 | \contentsline {section}{\numberline {1.2}Python Tanpa Instalasi - Google Colab}{8}{section.1.2}% 4 | \contentsline {section}{\numberline {1.3}Memulai}{9}{section.1.3}% 5 | \contentsline {section}{\numberline {1.4}Shell atau IDE}{11}{section.1.4}% 6 | \contentsline {section}{\numberline {1.5}Bahasa Python}{12}{section.1.5}% 7 | \contentsline {section}{\numberline {1.6}Kompleksitas}{14}{section.1.6}% 8 | \contentsline {section}{\numberline {1.7}List}{16}{section.1.7}% 9 | \contentsline {section}{\numberline {1.8}Input}{18}{section.1.8}% 10 | \contentsline {section}{\numberline {1.9}Pencabangan - Branching}{20}{section.1.9}% 11 | \contentsline {section}{\numberline {1.10}Pemrosesan Teks}{20}{section.1.10}% 12 | \contentsline {section}{\numberline {1.11}Membaca Berkas: topic generator}{21}{section.1.11}% 13 | \contentsline {section}{\numberline {1.12}Python3}{23}{section.1.12}% 14 | \contentsline {chapter}{\numberline {2}Koding Tingkat Medium}{25}{chapter.2}% 15 | \contentsline {section}{\numberline {2.1}Argumen CLI}{25}{section.2.1}% 16 | \contentsline {section}{\numberline {2.2}Numpy}{26}{section.2.2}% 17 | \contentsline {section}{\numberline {2.3}Matlplotlib}{28}{section.2.3}% 18 | \contentsline {section}{\numberline {2.4}Pandas}{35}{section.2.4}% 19 | \contentsline {section}{\numberline {2.5}OpenCV}{37}{section.2.5}% 20 | \contentsline {section}{\numberline {2.6}Kriptografi}{38}{section.2.6}% 21 | \contentsline {subsection}{\numberline {2.6.1}Fungsi Hash}{40}{subsection.2.6.1}% 22 | \contentsline {chapter}{\numberline {3}Triks}{41}{chapter.3}% 23 | \contentsline {section}{\numberline {3.1}Server Web}{41}{section.3.1}% 24 | \contentsline {section}{\numberline {3.2}Membaca Berkas Konfugurasi config.ini}{41}{section.3.2}% 25 | \contentsline {section}{\numberline {3.3}Menulis berkas dalam format Unicode}{43}{section.3.3}% 26 | \contentsline {chapter}{\numberline {4}Bibliography}{45}{chapter.4}% 27 | \contentsfinish 28 | -------------------------------------------------------------------------------- /referensi.bib: -------------------------------------------------------------------------------- 1 | % This file was created with JabRef 2.10. 2 | % Encoding: UTF-8 3 | 4 | 5 | @Book{tensorflowstarted, 6 | Title = {Getting Started with Tensorflow}, 7 | Author = {Giancarlo Zaccone}, 8 | Publisher = {Packt Publishing}, 9 | Year = {2016}, 10 | 11 | Owner = {budi}, 12 | Timestamp = {2017.12.09} 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tcpdump.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\zref@newlabel[2]{} 4 | \@setckpt{tcpdump}{ 5 | \setcounter{page}{7} 6 | \setcounter{equation}{0} 7 | \setcounter{enumi}{0} 8 | \setcounter{enumii}{0} 9 | \setcounter{enumiii}{0} 10 | \setcounter{enumiv}{0} 11 | \setcounter{footnote}{0} 12 | \setcounter{mpfootnote}{0} 13 | \setcounter{part}{0} 14 | \setcounter{chapter}{0} 15 | \setcounter{section}{0} 16 | \setcounter{subsection}{0} 17 | \setcounter{subsubsection}{0} 18 | \setcounter{paragraph}{0} 19 | \setcounter{subparagraph}{0} 20 | \setcounter{figure}{0} 21 | \setcounter{table}{0} 22 | \setcounter{Item}{0} 23 | \setcounter{bookmark@seq@number}{1} 24 | \setcounter{cp@cntr}{0} 25 | \setcounter{NAT@ctr}{0} 26 | \setcounter{@tufte@num@bibkeys}{0} 27 | \setcounter{Exercise}{0} 28 | \setcounter{Answer}{0} 29 | \setcounter{ExePart}{0} 30 | \setcounter{Question}{0} 31 | \setcounter{subQuestion}{0} 32 | \setcounter{subsubQuestion}{0} 33 | \setcounter{savedQuestion}{0} 34 | \setcounter{savedsubQuestion}{0} 35 | \setcounter{savedsubsubQuestion}{0} 36 | \setcounter{mdf@globalstyle@cnt}{0} 37 | \setcounter{mdfcountframes}{0} 38 | \setcounter{mdf@env@i}{0} 39 | \setcounter{mdf@env@ii}{0} 40 | \setcounter{mdf@zref@counter}{0} 41 | \setcounter{parentequation}{0} 42 | \setcounter{@pps}{1} 43 | \setcounter{@ppsavesec}{0} 44 | \setcounter{@ppsaveapp}{0} 45 | \setcounter{section@level}{0} 46 | } 47 | -------------------------------------------------------------------------------- /tricks.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\zref@newlabel[2]{} 4 | \@writefile{toc}{\contentsline {chapter}{\numberline {3}Triks}{41}{chapter.3}\protected@file@percent } 5 | \@writefile{lof}{\addvspace {10\p@ }} 6 | \@writefile{lot}{\addvspace {10\p@ }} 7 | \@writefile{toc}{\contentsline {section}{\numberline {3.1}Server Web}{41}{section.3.1}\protected@file@percent } 8 | \@writefile{toc}{\contentsline {section}{\numberline {3.2}Membaca Berkas Konfugurasi config.ini}{41}{section.3.2}\protected@file@percent } 9 | \@writefile{toc}{\contentsline {section}{\numberline {3.3}Menulis berkas dalam format Unicode}{43}{section.3.3}\protected@file@percent } 10 | \@setckpt{tricks}{ 11 | \setcounter{page}{45} 12 | \setcounter{equation}{0} 13 | \setcounter{enumi}{0} 14 | \setcounter{enumii}{0} 15 | \setcounter{enumiii}{0} 16 | \setcounter{enumiv}{0} 17 | \setcounter{footnote}{1} 18 | \setcounter{mpfootnote}{0} 19 | \setcounter{part}{0} 20 | \setcounter{chapter}{3} 21 | \setcounter{section}{3} 22 | \setcounter{subsection}{0} 23 | \setcounter{subsubsection}{0} 24 | \setcounter{paragraph}{0} 25 | \setcounter{subparagraph}{0} 26 | \setcounter{figure}{0} 27 | \setcounter{table}{0} 28 | \setcounter{Item}{0} 29 | \setcounter{bookmark@seq@number}{24} 30 | \setcounter{cp@cntr}{10} 31 | \setcounter{NAT@ctr}{0} 32 | \setcounter{@tufte@num@bibkeys}{0} 33 | \setcounter{Exercise}{0} 34 | \setcounter{Answer}{0} 35 | \setcounter{ExePart}{0} 36 | \setcounter{Question}{0} 37 | \setcounter{subQuestion}{0} 38 | \setcounter{subsubQuestion}{0} 39 | \setcounter{savedQuestion}{0} 40 | \setcounter{savedsubQuestion}{0} 41 | \setcounter{savedsubsubQuestion}{0} 42 | \setcounter{mdf@globalstyle@cnt}{0} 43 | \setcounter{mdfcountframes}{0} 44 | \setcounter{mdf@env@i}{0} 45 | \setcounter{mdf@env@ii}{0} 46 | \setcounter{mdf@zref@counter}{0} 47 | \setcounter{parentequation}{0} 48 | \setcounter{@pps}{0} 49 | \setcounter{@ppsavesec}{0} 50 | \setcounter{@ppsaveapp}{0} 51 | \setcounter{section@level}{0} 52 | } 53 | -------------------------------------------------------------------------------- /tricks.tex: -------------------------------------------------------------------------------- 1 | \chapter{Triks} 2 | Ada beberapa hal menarik dari Python. Pada bagian ini akan ditampilkan berbagai 3 | trik tersebut. 4 | 5 | \section{Server Web} 6 | Python dapat kita gunakan sebagai server web sederhana yang dapat memerikan 7 | list direktori. Fitur ini sering saya gunakan untuk transfer berkas antar 8 | mesin. Misalnya saya ingin mengambil sebuah berkas dari satu komputer ke 9 | komputer yang lain. Maka komputer dimana berkas tersebut berada saya jalankan 10 | perintah ini (pada direktori dimana berkas tersebut berada). 11 | 12 | \begin{verbatim} 13 | python -m http.server 8008 14 | \end{verbatim} 15 | 16 | Perintah di atas akan membuat sebuah server web yang berjalan pada {\em port} 17 | 8008. Anda dapat menggunakan port yang berbeda. 18 | Akan ditampilkan daftar berkas yang ada di direktori tersebut. Saya tinggal 19 | memilih berkas yang dimaksudkan dan {\em Save as ...}. 20 | 21 | Fitur server web ini juga sering saya gunakan untuk proses {\em debugging} 22 | sebuah aplikasi yang menggunakan protokol web. Untuk melihat data yang 23 | dikirimkan oleh aplikasi tersebut, saya arahkan dia ke web server ini dan 24 | kemudian saya perhatikan apa yang ditampilkan (yang diminta oleh aplikasi 25 | tersebut). 26 | 27 | \section{Membaca Berkas Konfugurasi config.ini} 28 | Seringkali ada kebutuhan untuk menyimpan {\em credential} (userid, password) 29 | dalam aplikasi. Sebagai contoh, kita ingin membuat koneksi ke server lain 30 | (server database, server FTP, dan sejenisnya) maka dibutuhkan informasi 31 | tentang nama atau nomor IP dari server yang dituju, userid dan password, 32 | dan informasi lainnya lagi. 33 | Seringkali informasi ini ditanam di dalam kode (source code). 34 | 35 | Apa beberapa masalah terkait dengan pendekatan ini (menanam credential) 36 | di dalam kode sumber. 37 | Pertama, jika terjadi perubahan (misal ada pergantian nomor IP dari server 38 | yang dituju) maka kita harus mencari di dalam kode mana saja terdapat 39 | penanaman informasi tersebut dan tentu saja harus diperbaharui. 40 | Bayangkan kalau informasi ini terdapat di beberapa berkas. 41 | Bagaimana kita tahu itu ada dimana? 42 | Jika konfigurasi ini hanya ada di satu berkas, misalnya di berkas 43 | ``config.ini'', maka operator hanya perlu melakukan perubahaan di berkas ini. 44 | 45 | Kedua, perubahan terhadap kode sangat berisiko. Beberapa kali terjadi 46 | kasus seseorang mengubah kode dari sebuah aplikasi (dengan bayangan 47 | minor update), ternyata aplikasi menjadi tidak berjalan. 48 | Ini dapat terjadi ketika update kekurangan tanda petik, misalnya, 49 | sehingga aplikasi malah menjadi ``error''. 50 | 51 | Jika kode ingin dibagikan, misal menggunakan github, maka credential 52 | sudah terpisahkan dengan kode sehingga kemungkinan tersebar juga lebih kecil. 53 | Tentu saja masih mungkin terjadi jika berkas config.ini berada dalam 54 | direktori yang dibagikan (share) dan tidak dimasukkan ke dalam 55 | berkas (.gitignore) dalam kasus github. 56 | 57 | Berikut ini adalah contoh kode yang lazim ditemui, yaitu menanamkan 58 | {\em credential} di dalam kode sumber. Perhatikan bahwa alamat server, 59 | userid, dan password tertanam dalam kode. 60 | 61 | \begin{verbatim} 62 | from ftplib import FTP 63 | 64 | SERVER = '192.168.4.29' 65 | NAMA = 'jabar' 66 | GEMBOK = 'juara2020' 67 | 68 | ftp = FTP(SERVER) 69 | ftp.login(user=NAMA, passwd=GEMBOK) 70 | ftp.dir() 71 | ftp.quit() 72 | \end{verbatim} 73 | 74 | Cara yang lebih baik adalah dengan menyimpan credential tersebut 75 | ke dalam sebuah berkas konfigurasi. Berikut ini adalah sebuah 76 | contoh isi berkas ``config.ini''. 77 | 78 | \begin{verbatim} 79 | [aplikasiku] 80 | server = 192.168.4.29 81 | user = jabar 82 | password = juara2020 83 | [queue] 84 | server = rabbitmq-server 85 | user = rabbitku 86 | password = sangatrahasia6677 87 | \end{verbatim} 88 | 89 | Berkas ini dapat dibaca dari aplikasi dengan cara berikut, dengan asumsi 90 | bahwa berkas ``config.ini'' berada dalam direktori yang sama dengan 91 | aplikasi ini. Untuk lebih meningkatkan keamanan, seringkali letak berkas 92 | konfigurasi berada di luar struktur direktori ini (di atasnya). Jadi 93 | variabel CONF dapat diisi dengan ``../config.in''. 94 | 95 | 96 | \begin{verbatim} 97 | from ftplib import FTP 98 | from configparser import ConfigParser 99 | 100 | CONF='config.ini' 101 | config = ConfigParser() 102 | # return filename 103 | config.read(CONF) 104 | 105 | SERVER = config.get('aplikasiku','server') 106 | NAMA = config.get('aplikasiku','user') 107 | GEMBOK = config.get('aplikasiku','password') 108 | 109 | ftp = FTP(SERVER) 110 | ftp.login(user=NAMA, passwd=GEMBOK) 111 | ftp.dir() 112 | ftp.quit() 113 | \end{verbatim} 114 | 115 | Penjelasan mengenai ini ada dalam video berikut. 116 | \begin{verbatim} 117 | https://www.youtube.com/watch?v=jze3DC6ohRc 118 | \end{verbatim} 119 | 120 | 121 | \section{Menulis berkas dalam format Unicode} 122 | Unicode merupakan alternatif pengkodean karakter untuk karakter yang tidak 123 | terdapat di kode ASCII. Bagaimana membuat berkas yang berisi karaktor Unicode? 124 | Berikut ini adalah salah satu contohnya. 125 | 126 | \begin{verbatim} 127 | unicode_text = u'BUDI Rahardjo' 128 | myencoded = unicode_text.encode('utf-16-le') 129 | #myencoded = unicode_text.encode('utf-16-be') 130 | 131 | a_file = open("budi-unicode.txt", "wb") 132 | a_file.write(myencoded) 133 | 134 | a_file = open("budi-unicode.txt", "r", encoding='utf-16-le') 135 | #a_file = open("budi-unicode.txt", "r", encoding='utf-16-be') 136 | # reads contents of a file 137 | contents = a_file.read() 138 | print(contents) 139 | \end{verbatim} 140 | 141 | Kode di atas menyimpan string 'Budi Rahardjo' ke dalam sebuah berkas dalam 142 | format UTF-16 dengan enkoding {\em little endian} (le) atau {\em big endian} 143 | (be)\footnote{Mengenai little endian atau big endian akan dibahas secara terpisah.}. 144 | Untuk melihat bagaimana data tersebut disimpan dalam berkas, 145 | dapat digunakan peritah ``hexdump'' atau ``xxd''. 146 | Perhatikan bahwa jika Anda menggunakan LE atau BE posisi bytes akan tertukar. 147 | Silahkan dicoba. 148 | 149 | \begin{verbatim} 150 | hexdump budi-unicode.txt 151 | 152 | 0000000 0042 0055 0044 0049 0020 0052 0061 0068 153 | 0000010 0061 0072 0064 006a 006f 154 | 000001a 155 | \end{verbatim} -------------------------------------------------------------------------------- /tufte-book.cls: -------------------------------------------------------------------------------- 1 | \NeedsTeXFormat{LaTeX2e}[1994/06/01] 2 | 3 | \ProvidesClass{tufte-book}[2015/06/30 v3.5.3 Tufte-book class] 4 | 5 | %% 6 | % Declare we're tufte-book 7 | \newcommand{\@tufte@class}{book}% the base LaTeX class (defaults to the book style) 8 | \newcommand{\@tufte@pkgname}{tufte-book}% the name of the package (defaults to tufte-handout) 9 | 10 | %% 11 | % Load the common style elements 12 | \input{tufte-common.def} 13 | 14 | 15 | %% 16 | % Set up any book-specific stuff now 17 | 18 | %% 19 | % The front matter in Tufte's /Beautiful Evidence/ contains everything up 20 | % to the opening page of Chapter 1. The running heads, when they appear, 21 | % contain only the (arabic) page number in the outside corner. 22 | %\newif\if@mainmatter \@mainmattertrue 23 | \renewcommand\frontmatter{% 24 | \if@openright% 25 | \cleardoublepage% 26 | \else% 27 | \clearpage% 28 | \fi% 29 | \@mainmatterfalse% 30 | \pagenumbering{arabic}% 31 | %\pagestyle{plain}% 32 | \fancyhf{}% 33 | \ifthenelse{\boolean{@tufte@twoside}}% 34 | {\fancyhead[LE,RO]{\thepage}}% 35 | {\fancyhead[RE,RO]{\thepage}}% 36 | } 37 | 38 | 39 | %% 40 | % The main matter in Tufte's /Beautiful Evidence/ doesn't restart the page 41 | % numbering---it continues where it left off in the front matter. 42 | \renewcommand\mainmatter{% 43 | \if@openright% 44 | \cleardoublepage% 45 | \else% 46 | \clearpage% 47 | \fi% 48 | \@mainmattertrue% 49 | \fancyhf{}% 50 | \ifthenelse{\boolean{@tufte@twoside}}% 51 | {% two-side 52 | \renewcommand{\chaptermark}[1]{\markboth{##1}{}}% 53 | \fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plaintitle}}}% book title 54 | \fancyhead[RO]{\smallcaps{\newlinetospace{\leftmark}}\quad\thepage}% chapter title 55 | }% 56 | {% one-side 57 | \fancyhead[RE,RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}% book title 58 | }% 59 | } 60 | 61 | 62 | %% 63 | % The back matter contains appendices, indices, glossaries, endnotes, 64 | % bibliographies, list of contributors, illustration credits, etc. 65 | \renewcommand\backmatter{% 66 | \if@openright% 67 | \cleardoublepage% 68 | \else% 69 | \clearpage% 70 | \fi% 71 | \@mainmatterfalse% 72 | } 73 | 74 | %% 75 | % Only show the chapter titles in the table of contents 76 | \setcounter{tocdepth}{0} 77 | 78 | %% 79 | % If there is a `tufte-book-local.sty' file, load it. 80 | 81 | \IfFileExists{tufte-book-local.tex}{% 82 | \@tufte@info@noline{Loading tufte-book-local.tex}% 83 | \input{tufte-book-local}% 84 | }{} 85 | 86 | %% 87 | % End of file 88 | \endinput 89 | --------------------------------------------------------------------------------