├── 2-neural-nets
├── __init__.py
├── README.md
├── sigmoid.py
├── softmax.py
├── gradient_checker.py
├── word2vec.py
└── two_layer_sigmoidal_net.py
├── .python-version
├── .gitignore
├── 0-libraries
├── numpy-exercises
│ ├── .gitattributes
│ ├── README.md
│ ├── LICENSE
│ ├── 10-set-routines.ipynb
│ ├── 03-numpy-help-functions.ipynb
│ ├── 09-random-sampling.ipynb
│ ├── Set_routines_Solutions.ipynb
│ ├── 07-logic-functions.ipynb
│ ├── Logic_functions_Solutions.ipynb
│ ├── Random_sampling_Solutions.ipynb
│ ├── 11-sorting-searching-counting.ipynb
│ ├── Sorting_searching_and_counting_Solutions.ipynb
│ └── 05-input-and-output.ipynb
├── pytorch-exercises
│ ├── Chapter1_Tensors
│ │ ├── temp.pt
│ │ ├── 2-random-sampling.ipynb
│ │ ├── 2-random-sampling-solution.ipynb
│ │ └── 4-statistics.ipynb
│ ├── LICENSE
│ └── README.md
└── README.md
├── 5-rnns-cnns
└── README.md
├── 1-machine-learning
└── README.md
├── 3-rnns
├── data
│ └── names
│ │ ├── Vietnamese.txt
│ │ ├── Korean.txt
│ │ ├── Portuguese.txt
│ │ ├── Scottish.txt
│ │ ├── Polish.txt
│ │ ├── Chinese.txt
│ │ ├── Greek.txt
│ │ ├── Irish.txt
│ │ ├── French.txt
│ │ ├── Spanish.txt
│ │ ├── Dutch.txt
│ │ ├── Czech.txt
│ │ ├── German.txt
│ │ ├── Italian.txt
│ │ └── Japanese.txt
├── README.md
└── rnn.py
├── 4-cnns
├── README.md
└── cnn.py
├── README.md
└── simplest-gan
├── gan.py
└── README.md
/2-neural-nets/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.python-version:
--------------------------------------------------------------------------------
1 | deep-learning
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .ipynb_checkpoints
2 | scratch.ipynb
3 | __pycache__
4 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/.gitattributes:
--------------------------------------------------------------------------------
1 | * linguist-language=Python
2 |
--------------------------------------------------------------------------------
/0-libraries/pytorch-exercises/Chapter1_Tensors/temp.pt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JasonBenn/deep-learning-implementations/HEAD/0-libraries/pytorch-exercises/Chapter1_Tensors/temp.pt
--------------------------------------------------------------------------------
/2-neural-nets/README.md:
--------------------------------------------------------------------------------
1 | ## Neural net components: softmax, batchnorm, dropout
2 |
3 | ### Learning Goals
4 |
5 | - Understand key components of common neural networks
6 | - Understand the limitations of these techniques
7 |
8 | ### Exercises
9 |
10 | - cs231n: 2-3: Dropout
11 | - cs231n: 2-2: Batch Normalization
12 | - cs231n: 1-4: [two-layer sigmoidal net](two-layer-sigmoidal-net.py)
13 | - cs231n: 1-3: [gradient checker](gradient-checker.py)
14 | - cs224d: 1-2: [sigmoid](sigmoid.py)
15 | - cs224d: 1-1: [softmax](softmax.py)
16 |
--------------------------------------------------------------------------------
/5-rnns-cnns/README.md:
--------------------------------------------------------------------------------
1 | ## Combined feature representations, VQA, captioning, saliency maps
2 |
3 | ### Learning Goals
4 |
5 | - Understand tradeoffs between various architectures for combining textual and visual feature representations
6 | - Understand advanced usages of attention
7 |
8 | ### Exercises
9 |
10 | - fast.ai: 10-11: DeViSE
11 | - cs231n: 3-3 (15%): Network Visualization: Saliency maps, Class Visualization, and Fooling Images
12 | - cs231n: 3-2 (30%): Image Captioning with LSTMs
13 | - cs231n: 3-1 (25%): Image Captioning with Vanilla RNNs
14 |
--------------------------------------------------------------------------------
/2-neural-nets/sigmoid.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf8 -*-
2 |
3 | import numpy as np
4 |
5 | def sigmoid(x):
6 | return 1/(1 + np.exp(-x))
7 |
8 | def sigmoid_grad(f):
9 | # Calculus is neat :)
10 | return f - np.power(f, 2)
11 |
12 | def test_sigmoid():
13 | x = np.array([[1, 2], [-1, -2]])
14 | f = sigmoid(x)
15 | g = sigmoid_grad(f)
16 | assert np.allclose([[0.73105858, 0.88079708], [0.26894142, 0.11920292]], f)
17 | print("✅")
18 | assert np.allclose([[0.19661193, 0.10499359], [0.19661193, 0.10499359]], g)
19 | print("✅")
20 |
21 | if __name__ == "__main__":
22 | test_sigmoid()
23 |
--------------------------------------------------------------------------------
/1-machine-learning/README.md:
--------------------------------------------------------------------------------
1 | ## Machine learning: linear algebra, non-deep classifiers
2 |
3 | ### Learning Goals
4 |
5 | - Understand what is possible with machine learning that isn't deep; when to refrain from reaching for neural nets
6 | - Understand practical numerical linear algebra
7 |
8 | ### Exercises
9 |
10 | - cs20si 1-2: logistic regression for coronary heart disease prediction
11 | - fast.ai linalg 7: PageRank with eigendecompositions
12 | - fast.ai linalg 4-6: Linear Regression
13 | - fast.ai linalg 3: Background Removal with Robust PCA
14 | - fast.ai linalg 2: Topic Modeling with NMF and SVD
15 | - cs231n: 1-2: Training a Support Vector Machine
16 | - cs231n: 1-1: k-Nearest Neighbor classifier
17 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Vietnamese.txt:
--------------------------------------------------------------------------------
1 | Nguyen
2 | Tron
3 | Le
4 | Pham
5 | Huynh
6 | Hoang
7 | Phan
8 | Vu
9 | Vo
10 | Dang
11 | Bui
12 | Do
13 | Ho
14 | Ngo
15 | Duong
16 | Ly
17 | An
18 | an
19 | Bach
20 | Banh
21 | Cao
22 | Chau
23 | Chu
24 | Chung
25 | Chu
26 | Diep
27 | Doan
28 | Dam
29 | Dao
30 | Dinh
31 | Doan
32 | Giang
33 | Ha
34 | Han
35 | Kieu
36 | Kim
37 | La
38 | Lac
39 | Lam
40 | Lieu
41 | Luc
42 | Luong
43 | Luu
44 | Ma
45 | Mach
46 | Mai
47 | Nghiem
48 | Phi
49 | Pho
50 | Phung
51 | Quach
52 | Quang
53 | Quyen
54 | Ta
55 | Thach
56 | Thai
57 | Sai
58 | Thi
59 | Than
60 | Thao
61 | Thuy
62 | Tieu
63 | To
64 | Ton
65 | Tong
66 | Trang
67 | Trieu
68 | Trinh
69 | Truong
70 | Van
71 | Vinh
72 | Vuong
73 | Vuu
74 |
--------------------------------------------------------------------------------
/0-libraries/README.md:
--------------------------------------------------------------------------------
1 | ## Libraries: numpy, PyTorch, TensorFlow
2 |
3 | ### Learning Goals
4 |
5 | - Understand the libraries I'll be using with every paper implementation
6 | - Understand the strengths of each of TensorFlow and PyTorch, and when to reach for one or the other
7 |
8 | ### Exercises
9 |
10 | - [PyTorch mini tutorials](https://github.com/vinhkhuc/PyTorch-Mini-Tutorials)
11 | - [Simple PyTorch examples](https://github.com/jcjohnson/pytorch-examples)
12 | - [Pytorch Exercises](https://github.com/Kyubyong/pytorch_exercises)
13 | - [Kyubyong's Numpy Exercises](https://github.com/Kyubyong/numpy_exercises)
14 | - [100 numpy exercises](https://github.com/rougier/numpy-100)
15 | - [TensorFlow Exercises](https://github.com/Kyubyong/tensorflow-exercises)
16 |
--------------------------------------------------------------------------------
/4-cnns/README.md:
--------------------------------------------------------------------------------
1 | ## Image classification, convolutional networks, image segmentation, generative models
2 |
3 | ### Learning Goals
4 |
5 | - Understand conv net best practices, tradeoffs of hyperparameter selections
6 | - Understand fully convolutional nets and their advantages over other architectures
7 | - Understand how to architect and train generative models
8 |
9 | ### Exercises
10 |
11 | - cs231n: 3-5: Generative Adversarial Networks
12 | - fast.ai: 14: 100-layers Tiramisu: Fully Convolutional Densenets, for Image Segmentation
13 | - cs20si 2: Style Transfer
14 | - cs231n: 3-4: Style Transfer
15 | - fast.ai: 8-9: Neural Style Transfer
16 | - cs231n: 2-5: PyTorch / TensorFlow on CIFAR-10
17 | - cs231n: 2-4: Convolutional Networks
18 | - cs231n: 2-1: Fully-connected Neural Network
19 | - cs231n: 1-5: Higher Level Representations: Image Features
20 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/README.md:
--------------------------------------------------------------------------------
1 | Thanks for the great study material Kyubyong!
2 |
3 | ## Author's notes:
4 |
5 | # NumPy Exercises
6 |
7 | In numerical computing in python, NumPy is essential. I'm writing simple (a few lines for each problem) but hopefully helpful exercises based on each of numpy's functions. The outline will be as follows.
8 |
9 | * Array creation routines (DONE)
10 | * Array manipulation routines (DONE)
11 | * String operations (DONE)
12 | * Numpy-specific help functions (DONE)
13 | * Indexing routines (WIP)
14 | * Input and output (DONE)
15 | * Linear algebra (numpy.linalg) (DONE)
16 | * Logic functions (DONE)
17 | * Mathematical functions (DONE)
18 | * Random sampling (numpy.random) (DONE)
19 | * Set routines (DONE)
20 | * Sorting, searching, and counting (DONE)
21 | * Statistics (DONE)
22 |
23 | Nov., 2016
24 | Kyubyong
25 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Korean.txt:
--------------------------------------------------------------------------------
1 | Ahn
2 | Baik
3 | Bang
4 | Byon
5 | Cha
6 | Chang
7 | Chi
8 | Chin
9 | Cho
10 | Choe
11 | Choi
12 | Chong
13 | Chou
14 | Chu
15 | Chun
16 | Chung
17 | Chweh
18 | Gil
19 | Gu
20 | Gwang
21 | Ha
22 | Han
23 | Ho
24 | Hong
25 | Hung
26 | Hwang
27 | Hyun
28 | Jang
29 | Jeon
30 | Jeong
31 | Jo
32 | Jon
33 | Jong
34 | Jung
35 | Kang
36 | Kim
37 | Ko
38 | Koo
39 | Ku
40 | Kwak
41 | Kwang
42 | Lee
43 | Li
44 | Lim
45 | Ma
46 | Mo
47 | Moon
48 | Nam
49 | Ngai
50 | Noh
51 | Oh
52 | Pae
53 | Pak
54 | Park
55 | Ra
56 | Rhee
57 | Rheem
58 | Ri
59 | Rim
60 | Ron
61 | Ryom
62 | Ryoo
63 | Ryu
64 | San
65 | Seo
66 | Seok
67 | Shim
68 | Shin
69 | Shon
70 | Si
71 | Sin
72 | So
73 | Son
74 | Song
75 | Sook
76 | Suh
77 | Suk
78 | Sun
79 | Sung
80 | Tsai
81 | Wang
82 | Woo
83 | Yang
84 | Yeo
85 | Yeon
86 | Yi
87 | Yim
88 | Yoo
89 | Yoon
90 | You
91 | Youj
92 | Youn
93 | Yu
94 | Yun
95 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Portuguese.txt:
--------------------------------------------------------------------------------
1 | Abreu
2 | Albuquerque
3 | Almeida
4 | Alves
5 | Araújo
6 | Araullo
7 | Barros
8 | Basurto
9 | Belo
10 | Cabral
11 | Campos
12 | Cardozo
13 | Castro
14 | Coelho
15 | Costa
16 | Crespo
17 | Cruz
18 | D'cruz
19 | D'cruze
20 | Delgado
21 | De santigo
22 | Duarte
23 | Estéves
24 | Fernandes
25 | Ferreira
26 | Ferreiro
27 | Ferro
28 | Fonseca
29 | Franco
30 | Freitas
31 | Garcia
32 | Gaspar
33 | Gomes
34 | Gouveia
35 | Guerra
36 | Henriques
37 | Lobo
38 | Machado
39 | Madeira
40 | Magalhães
41 | Maria
42 | Mata
43 | Mateus
44 | Matos
45 | Medeiros
46 | Melo
47 | Mendes
48 | Moreno
49 | Nunes
50 | Palmeiro
51 | Paredes
52 | Pereira
53 | Pinheiro
54 | Pinho
55 | Ramires
56 | Ribeiro
57 | Rios
58 | Rocha
59 | Rodrigues
60 | Romão
61 | Rosario
62 | Salazar
63 | Santana
64 | Santiago
65 | Santos
66 | Serafim
67 | Silva
68 | Silveira
69 | Simões
70 | Soares
71 | Souza
72 | Torres
73 | Vargas
74 | Ventura
75 |
--------------------------------------------------------------------------------
/3-rnns/README.md:
--------------------------------------------------------------------------------
1 | ## Natural language processing, word2vec + subwords, NER, neural machine translation, attention
2 |
3 | ### Learning Goals
4 |
5 | - Understand state-of-the-art algorithms for generating language embeddings
6 | - Basic familiarity with old-school NLP feature engineering techniques
7 | - Understand tradeoffs to a variety of attentional architectures
8 | - Understand common long-term dependency moduules: GRUs & LSTMs
9 | - Experiment with impact of initialization on deep RNN architectures
10 |
11 | ### Exercises
12 |
13 | - cs20si 3: A TensorFlow chatbot
14 | - fast.ai: 13: Neural Machine Translation of Rare Words with Subword Units
15 | - fast.ai: 12: Neural Machine Translation by Jointly Learning to Align and Translate
16 | - cs224d: 3-1: Recursive Neural Network
17 | - cs224d: 2-3: TensorFlow RNN Language Model
18 | - cs224d: 2-2: TensorFlow NER Window Model
19 | - cs224d: 1-4: Sentiment Analysis
20 | - cs224d: 1-3: word2vec
21 | - cs20si 1-3: word2vec
22 |
--------------------------------------------------------------------------------
/2-neural-nets/softmax.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf8 -*-
2 |
3 | import numpy as np
4 | import random
5 |
6 | def softmax(x):
7 | # Softmax is invariant to bias: you can shift the entire input up or down by a scalar and the output will still be the same!
8 | # Because using a large input as an exponent will cause overflow errors, but using a very negative input as an exponent will just result in 0, we take advantage of this property to avoid overflows.
9 | # Subtract the largest value from the entire array.
10 | scaled = x - np.max(x)
11 | e_to_x = np.exp(scaled)
12 | return e_to_x / e_to_x.sum()
13 |
14 | def test_softmax():
15 | test1 = softmax(np.array([1,2]))
16 | assert np.allclose(test1, np.array([0.26894142, 0.73105858]))
17 | print("✅")
18 |
19 | test2 = softmax(np.array([[1001,1002],[3,4]]))
20 | assert np.allclose(test2, np.array([[0.26894142, 0.73105858], [0, 0]]))
21 | print("✅")
22 |
23 | test3 = softmax(np.array([[-1001,-1002]]))
24 | assert np.allclose(test3, np.array([0.73105858, 0.26894142]))
25 | print("✅")
26 |
27 | if __name__ == "__main__":
28 | test_softmax()
29 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Kyubyong Park
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/0-libraries/pytorch-exercises/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Kyubyong Park
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Scottish.txt:
--------------------------------------------------------------------------------
1 | Smith
2 | Brown
3 | Wilson
4 | Campbell
5 | Stewart
6 | Thomson
7 | Robertson
8 | Anderson
9 | Macdonald
10 | Scott
11 | Reid
12 | Murray
13 | Taylor
14 | Clark
15 | Ross
16 | Watson
17 | Morrison
18 | Paterson
19 | Young
20 | Mitchell
21 | Walker
22 | Fraser
23 | Miller
24 | Mcdonald
25 | Gray
26 | Henderson
27 | Hamilton
28 | Johnston
29 | Duncan
30 | Graham
31 | Ferguson
32 | Kerr
33 | Davidson
34 | Bell
35 | Cameron
36 | Kelly
37 | Martin
38 | Hunter
39 | Allan
40 | Mackenzie
41 | Grant
42 | Simpson
43 | Mackay
44 | Mclean
45 | Macleod
46 | Black
47 | Russell
48 | Marshall
49 | Wallace
50 | Gibson
51 | Kennedy
52 | Gordon
53 | Burns
54 | Sutherland
55 | Stevenson
56 | Munro
57 | Milne
58 | Watt
59 | Murphy
60 | Craig
61 | Wood
62 | Muir
63 | Wright
64 | Mckenzie
65 | Ritchie
66 | Johnstone
67 | Sinclair
68 | White
69 | Mcmillan
70 | Williamson
71 | Dickson
72 | Hughes
73 | Cunningham
74 | Mckay
75 | Bruce
76 | Millar
77 | Crawford
78 | Mcintosh
79 | Douglas
80 | Docherty
81 | King
82 | Jones
83 | Boyle
84 | Fleming
85 | Mcgregor
86 | Aitken
87 | Christie
88 | Shaw
89 | Maclean
90 | Jamieson
91 | Mcintyre
92 | Hay
93 | Lindsay
94 | Alexander
95 | Ramsay
96 | Mccallum
97 | Whyte
98 | Jackson
99 | Mclaughlin
100 | Hill
101 |
--------------------------------------------------------------------------------
/2-neural-nets/gradient_checker.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf8 -*-
2 |
3 | import numpy as np
4 | import random
5 | from sklearn.metrics import log_loss
6 | import sys
7 |
8 | def gradcheck_naive(f, x):
9 | """
10 | Check that the gradient for a function f is correct
11 | """
12 |
13 | rndstate = random.getstate()
14 | random.setstate(rndstate)
15 | fx, grad = f(x)
16 | h = 1e-4
17 |
18 |
19 |
20 | # Iterate over all indexes in x
21 | it = np.nditer(x, flags=['multi_index'], op_flags=['readwrite'])
22 | while not it.finished:
23 | ix = it.multi_index
24 |
25 | # This approximates the derivative of this function at x[ix].
26 | slightly_higher, _ = f(x[ix] + h)
27 | slightly_lower, _ = f(x[ix] - h)
28 | numgrad = (slightly_higher - slightly_lower) / (2 * h)
29 |
30 | reldiff = abs(numgrad - grad[ix]) / max(1, abs(numgrad), abs(grad[ix]))
31 |
32 | if reldiff > 1e-5:
33 | print("❌ First gradient error found at index %s" % str(ix))
34 | print("Your gradient: %f \t Numerical gradient: %f" % (grad[ix], numgrad))
35 | sys.exit(0)
36 |
37 | it.iternext() # Step to next dimension
38 |
39 | def sanity_check():
40 | quad = lambda x: (np.sum(x ** 2), x * 2)
41 |
42 | gradcheck_naive(quad, np.array(123.456)) # scalar test
43 | print("✅")
44 | gradcheck_naive(quad, np.random.randn(3,)) # 1-D test
45 | print("✅")
46 | gradcheck_naive(quad, np.random.randn(4,5)) # 2-D test
47 | print("✅")
48 |
49 | if __name__ == "__main__":
50 | sanity_check()
51 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Polish.txt:
--------------------------------------------------------------------------------
1 | Adamczak
2 | Adamczyk
3 | Andrysiak
4 | Auttenberg
5 | Bartosz
6 | Bernard
7 | Bobienski
8 | Bosko
9 | Broż
10 | Brzezicki
11 | Budny
12 | Bukoski
13 | Bukowski
14 | Chlebek
15 | Chmiel
16 | Czajka
17 | Czajkowski
18 | Dubanowski
19 | Dubicki
20 | Dunajski
21 | Dziedzic
22 | Fabian
23 | Filipek
24 | Filipowski
25 | Gajos
26 | Gniewek
27 | Gomolka
28 | Gomulka
29 | Gorecki
30 | Górka
31 | Górski
32 | Grzeskiewicz
33 | Gwozdek
34 | Jagoda
35 | Janda
36 | Janowski
37 | Jaskolski
38 | Jaskulski
39 | Jedynak
40 | Jelen
41 | Jez
42 | Jordan
43 | Kaczka
44 | Kaluza
45 | Kamiński
46 | Kasprzak
47 | Kava
48 | Kedzierski
49 | Kijek
50 | Klimek
51 | Kosmatka
52 | Kowalczyk
53 | Kowalski
54 | Koziol
55 | Kozlow
56 | Kozlowski
57 | Krakowski
58 | Król
59 | Kumiega
60 | Lawniczak
61 | Lis
62 | Majewski
63 | Malinowski
64 | Maly
65 | Marek
66 | Marszałek
67 | Maslanka
68 | Mencher
69 | Miazga
70 | Michel
71 | Mikolajczak
72 | Mozdzierz
73 | Niemczyk
74 | Niemec
75 | Nosek
76 | Nowak
77 | Pakulski
78 | Pasternack
79 | Pasternak
80 | Paszek
81 | Piatek
82 | Piontek
83 | Pokorny
84 | Poplawski
85 | Róg
86 | Rudaski
87 | Rudawski
88 | Rusnak
89 | Rutkowski
90 | Sadowski
91 | Salomon
92 | Serafin
93 | Sienkiewicz
94 | Sierzant
95 | Sitko
96 | Skala
97 | Slaski
98 | Ślązak
99 | Ślusarczyk
100 | Ślusarski
101 | Smolák
102 | Sniegowski
103 | Sobol
104 | Sokal
105 | Sokolof
106 | Sokoloff
107 | Sokolofsky
108 | Sokolowski
109 | Sokolsky
110 | Sówka
111 | Stanek
112 | Starek
113 | Stawski
114 | Stolarz
115 | Szczepanski
116 | Szewc
117 | Szwarc
118 | Szweda
119 | Szwedko
120 | Walentowicz
121 | Warszawski
122 | Wawrzaszek
123 | Wiater
124 | Winograd
125 | Winogrodzki
126 | Wojda
127 | Wojewódka
128 | Wojewódzki
129 | Wronski
130 | Wyrick
131 | Wyrzyk
132 | Zabek
133 | Zawisza
134 | Zdunowski
135 | Zdunowski
136 | Zielinski
137 | Ziemniak
138 | Zientek
139 | Żuraw
140 |
--------------------------------------------------------------------------------
/0-libraries/pytorch-exercises/README.md:
--------------------------------------------------------------------------------
1 | # Pytorch Exercises
2 |
3 | Pytorch is one of the most popular deep learning libraries as of 2017. One possible way of familiarizing yourself with it, I think, is to practice with simple quizzes. That's where this project comes in. The outline will be as follows, though it's not fixed. If you find this helpful, you may like my other repos:
4 | * [NumPy exercises](https://github.com/Kyubyong/numpy_exercises)
5 | * [TensorFlow exercises](https://github.com/Kyubyong/tensorflow-exercises)
6 |
7 | CHAPTER 1. Tensors
8 | * Tensor Creation ([Quiz](Chapter1_Tensors/Tensor_Creation.ipynb) / [Sol.](Chapter1_Tensors/Tensor_Creation_solution.ipynb))
9 | * Tensor Transformations ([Quiz](Chapter1_Tensors/Tensor_Transformations.ipynb) / [Sol.](Chapter1_Tensors/Tensor_Transformations_solution.ipynb))
10 | * Random Sampling ([Quiz](Chapter1_Tensors/Random_Sampling.ipynb) / [Sol.](Chapter1_Tensors/Random_Sampling_solution.ipynb))
11 | * Math Operations ([Quiz](Chapter1_Tensors/Math_Operations.ipynb) / [Sol.](Chapter1_Tensors/Math_Operations_solution.ipynb))
12 | * Statistics ([Quiz](Chapter1_Tensors/Statistics.ipynb) / [Sol.](Chapter1_Tensors/Statistics_solution.ipynb))
13 | * Linear Algebra ([Quiz](Chapter1_Tensors/Linear_Algebra.ipynb) / [Sol.](Chapter1_Tensors/Linear_Algebra_solution.ipynb))
14 | * Variables ([Quiz](Chapter1_Tensors/Variables.ipynb) / [Sol.](Chapter1_Tensors/Variables_solution.ipynb))
15 |
16 | CHAPTER 2. Neural Networks
17 | * Linear Layers/Functions (WIP)
18 | * Convolution Layers/Functions (WIP)
19 | * Recurrent Layers (WIP)
20 | * Pooling Layers/Functions (WIP)
21 | * Dropout Layers/Functions (WIP)
22 | * Padding Layers (WIP)
23 | * Normalization Layers/Functions (WIP)
24 | * Activations (WIP)
25 | * Sparse Layers (WIP)
26 | * Loss (WIP)
27 | * Distance (WIP)
28 | * Initialization (WIP)
29 | * Optimization (WIP)
30 | * Utilities (WIP)
31 |
32 |
33 |
34 |
35 | Sep., 2017
36 | Created by Kyubyong
37 | Reviewed by [yj](https://github.com/yjchoe)
38 |
--------------------------------------------------------------------------------
/2-neural-nets/word2vec.py:
--------------------------------------------------------------------------------
1 | import torch
2 | from torch import LongTensor, FloatTensor
3 | from torch.autograd import Variable
4 | from itertools import islice
5 |
6 | words = ["a", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog"]
7 | one_hot_encodings = torch.eye(len(words))
8 | word_to_one_hot = {}
9 | for i, word in enumerate(words):
10 | word_to_one_hot[word] = one_hot_encodings[i]
11 |
12 | words_to_indexes = { word: i for i, word in enumerate(words) }
13 |
14 |
15 | def window(seq, n=2):
16 | "Returns a sliding window (of width n) over data from the iterable"
17 | " s -> (s0,s1,...s[n-1]), (s1,s2,...,sn), ... "
18 | it = iter(seq)
19 | result = tuple(islice(it, n))
20 | if len(result) == n:
21 | yield result
22 | for elem in it:
23 | result = result[1:] + (elem,)
24 | yield result
25 |
26 |
27 | class Word2Vec(torch.nn.Module):
28 | def __init__(self, embedding_size, vocab_size, cbow_window_size=4):
29 | super(Word2Vec, self).__init__()
30 | self.embedding = torch.nn.Embedding(vocab_size, embedding_size)
31 | self.layer1 = torch.nn.Linear(embedding_size * cbow_window_size, embedding_size)
32 | self.layer2 = torch.nn.Linear(embedding_size, vocab_size)
33 |
34 | def forward(self, inputs):
35 | input_embeddings = self.embedding(inputs).view((1, -1)) # Reshape to 36,1
36 | activations_1 = torch.sigmoid(self.layer1(input_embeddings))
37 | return torch.nn.Softmax()(self.layer2(activations_1))
38 |
39 | EMBEDDING_SIZE = 200
40 | model = Word2Vec(EMBEDDING_SIZE, len(words))
41 |
42 | loss_fn = torch.nn.MSELoss()
43 | optimizer = torch.optim.SGD(model.parameters(), lr=.001)
44 |
45 | for epoch in range(5):
46 | word_iter = window(words, 5)
47 | total_loss = 0
48 | for i in range(5):
49 | optimizer.zero_grad()
50 | example = next(word_iter)
51 | word_indexes = [words_to_indexes[word] for word in example]
52 | inputs = Variable(torch.cat((LongTensor(word_indexes[:2]), LongTensor(word_indexes[3:]))))
53 | label = Variable(word_to_one_hot[example[2]])
54 | predictions = model(inputs)
55 | loss = loss_fn(predictions, label)
56 | loss.backward()
57 | optimizer.step()
58 | total_loss += loss.data
59 | print("epoch {} loss: {}".format(epoch, total_loss))
60 |
61 | print("✅")
62 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Deep Learning paper and algorithm implementations
2 |
3 | This repo collects exercises and provides code for deep learning papers and algorithms. Implementations are loosely organized by topic and grouped into folders. In addition to implementations, each folder contains a README with learning goals and a list of exercises. Both folders and exercises are arranged in increasing order of complexity.
4 |
5 | All code is written in Python 3 and implementations are in either TensorFlow or PyTorch.
6 |
7 | ### Table of Contents
8 |
9 | - 🙇 [Libraries: numpy, PyTorch, TensorFlow](0-libraries)
10 | - 🎯 [Machine learning: linear algebra, non-deep classifiers](1-machine-learning)
11 | - 🔑 [Neural net components: backprop, sigmoid, softmax, batchnorm, dropout](2-neural-nets)
12 | - 📚 [Natural language processing, word2vec + subwords, NER, neural machine translation, attention](3-rnns)
13 | - 🎨 [Image classification, convolutional networks, image segmentation, generative models](4-cnns)
14 | - 💬 [Combined feature representations, VQA, captioning, saliency maps](5-rnns-cnns)
15 |
16 | ### Implemented
17 |
18 | - Vanilla GAN [[code](simplest-gan)]
19 | - VGG [[code](4-cnns/cnn.py)]
20 | - Char-level RNN [[code](3-rnns/rnn.py)]
21 | - Word2Vec [[code](2-neural-nets/word2vec.py)]
22 | - Simple two-layer neural net [[code](2-neural-nets/two_layer_sigmoidal_net.py)]
23 | - Numerical gradient checker [[code](2-neural-nets/gradient_checker.py)]
24 | - Sigmoid [[code](2-neural-nets/sigmoid.py)]
25 | - Softmax [[code](2-neural-nets/softmax.py)]
26 | - Pytorch Exercises [[notebook](0-libraries/pytorch-exercises)]
27 | - Kyubyong's numpy exercises [[notebook](0-libraries/numpy-exercises)]
28 |
29 | ### Resources
30 |
31 | #### Classes:
32 |
33 | - [fast.ai 1](http://course.fast.ai/): Practical Deep Learning For Coders
34 | - [fast.ai 2](http://course.fast.ai/): Cutting Edge Deep Learning For Coders
35 | - [fast.ai linalg](https://github.com/fastai/numerical-linear-algebra/blob/master/README.md): Computational Linear Algebra for Coders
36 | - [CS224d](http://cs224d.stanford.edu/syllabus.html): Deep Learning for Natural Language Processing
37 | - [CS231n](http://cs231n.stanford.edu/syllabus.html): Convolutional Neural Networks for Visual Recognition
38 |
39 | #### Textbooks:
40 |
41 | - [The Deep Learning Book](https://www.deeplearningbook.org/)
42 |
43 | #### Collections of implementations:
44 |
45 | - https://github.com/tensorflow/models
46 | - https://github.com/dennybritz/models
47 | - http://carpedm20.github.io
48 |
49 | ---
50 |
51 | Format inspired by [Denny Britz](https://github.com/dennybritz/reinforcement-learning/blob/master/README.md) (my chief innovation on his format is that I added emojis).
52 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Chinese.txt:
--------------------------------------------------------------------------------
1 | Ang
2 | Au-Yong
3 | Bai
4 | Ban
5 | Bao
6 | Bei
7 | Bian
8 | Bui
9 | Cai
10 | Cao
11 | Cen
12 | Chai
13 | Chaim
14 | Chan
15 | Chang
16 | Chao
17 | Che
18 | Chen
19 | Cheng
20 | Cheung
21 | Chew
22 | Chieu
23 | Chin
24 | Chong
25 | Chou
26 | Chu
27 | Cui
28 | Dai
29 | Deng
30 | Ding
31 | Dong
32 | Dou
33 | Duan
34 | Eng
35 | Fan
36 | Fei
37 | Feng
38 | Foong
39 | Fung
40 | Gan
41 | Gauk
42 | Geng
43 | Gim
44 | Gok
45 | Gong
46 | Guan
47 | Guang
48 | Guo
49 | Gwock
50 | Han
51 | Hang
52 | Hao
53 | Hew
54 | Hiu
55 | Hong
56 | Hor
57 | Hsiao
58 | Hua
59 | Huan
60 | Huang
61 | Hui
62 | Huie
63 | Huo
64 | Jia
65 | Jiang
66 | Jin
67 | Jing
68 | Joe
69 | Kang
70 | Kau
71 | Khoo
72 | Khu
73 | Kong
74 | Koo
75 | Kwan
76 | Kwei
77 | Kwong
78 | Lai
79 | Lam
80 | Lang
81 | Lau
82 | Law
83 | Lew
84 | Lian
85 | Liao
86 | Lim
87 | Lin
88 | Ling
89 | Liu
90 | Loh
91 | Long
92 | Loong
93 | Luo
94 | Mah
95 | Mai
96 | Mak
97 | Mao
98 | Mar
99 | Mei
100 | Meng
101 | Miao
102 | Min
103 | Ming
104 | Moy
105 | Mui
106 | Nie
107 | Niu
108 | Ou-Yang
109 | Ow-Yang
110 | Pan
111 | Pang
112 | Pei
113 | Peng
114 | Ping
115 | Qian
116 | Qin
117 | Qiu
118 | Quan
119 | Que
120 | Ran
121 | Rao
122 | Rong
123 | Ruan
124 | Sam
125 | Seah
126 | See
127 | Seow
128 | Seto
129 | Sha
130 | Shan
131 | Shang
132 | Shao
133 | Shaw
134 | She
135 | Shen
136 | Sheng
137 | Shi
138 | Shu
139 | Shuai
140 | Shui
141 | Shum
142 | Siew
143 | Siu
144 | Song
145 | Sum
146 | Sun
147 | Sze
148 | Tan
149 | Tang
150 | Tao
151 | Teng
152 | Teoh
153 | Thean
154 | Thian
155 | Thien
156 | Tian
157 | Tong
158 | Tow
159 | Tsang
160 | Tse
161 | Tsen
162 | Tso
163 | Tze
164 | Wan
165 | Wang
166 | Wei
167 | Wen
168 | Weng
169 | Won
170 | Wong
171 | Woo
172 | Xiang
173 | Xiao
174 | Xie
175 | Xing
176 | Xue
177 | Xun
178 | Yan
179 | Yang
180 | Yao
181 | Yap
182 | Yau
183 | Yee
184 | Yep
185 | Yim
186 | Yin
187 | Ying
188 | Yong
189 | You
190 | Yuan
191 | Zang
192 | Zeng
193 | Zha
194 | Zhan
195 | Zhang
196 | Zhao
197 | Zhen
198 | Zheng
199 | Zhong
200 | Zhou
201 | Zhu
202 | Zhuo
203 | Zong
204 | Zou
205 | Bing
206 | Chi
207 | Chu
208 | Cong
209 | Cuan
210 | Dan
211 | Fei
212 | Feng
213 | Gai
214 | Gao
215 | Gou
216 | Guan
217 | Gui
218 | Guo
219 | Hong
220 | Hou
221 | Huan
222 | Jian
223 | Jiao
224 | Jin
225 | Jiu
226 | Juan
227 | Jue
228 | Kan
229 | Kuai
230 | Kuang
231 | Kui
232 | Lao
233 | Liang
234 | Lu:
235 | Luo
236 | Man
237 | Nao
238 | Pian
239 | Qiao
240 | Qing
241 | Qiu
242 | Rang
243 | Rui
244 | She
245 | Shi
246 | Shuo
247 | Sui
248 | Tai
249 | Wan
250 | Wei
251 | Xian
252 | Xie
253 | Xin
254 | Xing
255 | Xiong
256 | Xuan
257 | Yan
258 | Yin
259 | Ying
260 | Yuan
261 | Yue
262 | Yun
263 | Zha
264 | Zhai
265 | Zhang
266 | Zhi
267 | Zhuan
268 | Zhui
269 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Greek.txt:
--------------------------------------------------------------------------------
1 | Adamidis
2 | Adamou
3 | Agelakos
4 | Akrivopoulos
5 | Alexandropoulos
6 | Anetakis
7 | Angelopoulos
8 | Antimisiaris
9 | Antipas
10 | Antonakos
11 | Antoniadis
12 | Antonopoulos
13 | Antonopoulos
14 | Antonopoulos
15 | Arvanitoyannis
16 | Avgerinos
17 | Banos
18 | Batsakis
19 | Bekyros
20 | Belesis
21 | Bertsimas
22 | Bilias
23 | Blades
24 | Bouloukos
25 | Brisimitzakis
26 | Bursinos
27 | Calogerakis
28 | Calpis
29 | Chellos
30 | Christakos
31 | Christodoulou
32 | Christou
33 | Chrysanthopoulos
34 | Chrysanthopoulos
35 | Comino
36 | Close
37 | Close
38 | Close
39 | Close
40 | Close
41 | Close
42 | Close
43 | Close
44 | Dalianis
45 | Danas
46 | Dasios
47 | Demakis
48 | Demarchis
49 | Demas
50 | Demetrious
51 | Dertilis
52 | Diakogeorgiou
53 | Dioletis
54 | Dounias
55 | Dritsas
56 | Drivakis
57 | Eatros
58 | Egonidis
59 | Eliopoulos
60 | Forakis
61 | Fotopoulos
62 | Fourakis
63 | Frangopoulos
64 | Galanopoulos
65 | Garofalis
66 | Gavril
67 | Gavrilopoulos
68 | Georgeakopoulos
69 | Geracimos
70 | Gianakopulos
71 | Giannakopoulos
72 | Giannakos
73 | Glynatsis
74 | Gomatos
75 | Grammatakakis
76 | Gravari
77 | Hadjiyianakies
78 | Hagias
79 | Haritopoulos
80 | Honjas
81 | Horiatis
82 | Houlis
83 | Jamussa
84 | Kaglantge
85 | Kalakos
86 | Kalogeria
87 | Kaloxylos
88 | Kanavos
89 | Kapsimalles
90 | Karahalios
91 | Karameros
92 | Karkampasis
93 | Karnoupakis
94 | Katsourinis
95 | Kefalas
96 | Kokkali
97 | Kokoris
98 | Kolovos
99 | Konstantatos
100 | Kosmas
101 | Kotsilimbas
102 | Kotsiopoulos
103 | Kouches
104 | Koulaxizis
105 | Koumanidis
106 | Kourempes
107 | Kouretas
108 | Kouropoulos
109 | Kouros
110 | Koustoubos
111 | Koutsoubos
112 | Kreskas
113 | Kringos
114 | Kyritsis
115 | Laganas
116 | Leontarakis
117 | Letsos
118 | Liatos
119 | Lillis
120 | Lolos
121 | Louverdis
122 | Makricosta
123 | Malihoudis
124 | Maneates
125 | Manos
126 | Manoukarakis
127 | Matsoukis
128 | Mentis
129 | Mersinias
130 | Metrofanis
131 | Michalaras
132 | Milionis
133 | Missiakos
134 | Moraitopoulos
135 | Nikolaou
136 | Nomikos
137 | Paitakes
138 | Paloumbas
139 | Panayiotopoulos
140 | Panoulias
141 | Pantelakos
142 | Pantelas
143 | Papadelias
144 | Papadopulos
145 | Papageorge
146 | Papoutsis
147 | Pappayiorgas
148 | Paraskevopoulos
149 | Paraskos
150 | Paschalis
151 | Patrianakos
152 | Patselas
153 | Pefanis
154 | Petimezas
155 | Petrakis
156 | Pezos
157 | Phocas
158 | Pispinis
159 | Polites
160 | Polymenakou
161 | Poniros
162 | Protopsaltis
163 | Rallis
164 | Rigatos
165 | Rorris
166 | Rousses
167 | Ruvelas
168 | Sakelaris
169 | Sakellariou
170 | Samios
171 | Sardelis
172 | Sfakianos
173 | Sklavenitis
174 | Sortras
175 | Sotiris
176 | Spyridis
177 | Stamatas
178 | Stamatelos
179 | Stavropoulos
180 | Strilakos
181 | Stroggylis
182 | Tableriou
183 | Taflambas
184 | Tassioglou
185 | Telis
186 | Tsoumada
187 | Theofilopoulos
188 | Theohari
189 | Totolos
190 | Tourna
191 | Tsahalis
192 | Tsangaris
193 | Tselios
194 | Tsogas
195 | Vamvakidis
196 | Varvitsiotes
197 | Vassilikos
198 | Vassilopulos
199 | Vlahos
200 | Vourlis
201 | Xydis
202 | Zaloumi
203 | Zouvelekis
204 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Irish.txt:
--------------------------------------------------------------------------------
1 | Adam
2 | Ahearn
3 | Aodh
4 | Aodha
5 | Aonghuis
6 | Aonghus
7 | Bhrighde
8 | Bradach
9 | Bradan
10 | Braden
11 | Brady
12 | Bran
13 | Brannon
14 | Brian
15 | Callaghan
16 | Caomh
17 | Carey
18 | Casey
19 | Cassidy
20 | Cathain
21 | Cathan
22 | Cathasach
23 | Ceallach
24 | Ceallachan
25 | Cearbhall
26 | Cennetig
27 | Ciardha
28 | Clark
29 | Cleirich
30 | Cleirigh
31 | Cnaimhin
32 | Coghlan
33 | Coilean
34 | Collins
35 | Colman
36 | Conall
37 | Conchobhar
38 | Conn
39 | Connell
40 | Connolly
41 | Cormac
42 | Corraidhin
43 | Cuidightheach
44 | Curran
45 | Dúbhshlaine
46 | Dalach
47 | Daly
48 | Damhain
49 | Damhan
50 | Delaney
51 | Desmond
52 | Devin
53 | Diarmaid
54 | Doherty
55 | Domhnall
56 | Donnchadh
57 | Donndubhan
58 | Donnell
59 | Donoghue
60 | Donovan
61 | Doyle
62 | Dubhain
63 | Dubhan
64 | Duncan
65 | Eoghan
66 | Eoin
67 | Eoin
68 | Faolan
69 | Farrell
70 | Fearghal
71 | Fergus
72 | Finn
73 | Finnegan
74 | Fionn
75 | Flanagan
76 | Flann
77 | Flynn
78 | Gallchobhar
79 | Gerald
80 | Giolla
81 | Gorman
82 | Hayden
83 | Ivor
84 | John
85 | Kavanagh
86 | Keefe
87 | Kelly
88 | Kennedy
89 | Lennon
90 | Login
91 | Macclelland
92 | Macdermott
93 | Maceachthighearna
94 | Macfarland
95 | Macghabhann
96 | Maciomhair
97 | Macshuibhne
98 | Madaidhin
99 | Madden
100 | Maguire
101 | Mahoney
102 | Maille
103 | Malone
104 | Manus
105 | Maolmhuaidh
106 | Mathghamhain
107 | Maurice
108 | Mcguire
109 | Mckay
110 | Mclain
111 | Mcmahon
112 | Mcnab
113 | Mcneil
114 | Meadhra
115 | Michael
116 | Milligan
117 | Mochan
118 | Mohan
119 | Molloy
120 | Monahan
121 | Mooney
122 | Muirchertach
123 | Mullen
124 | Mulryan
125 | Murchadh
126 | Murphy
127 | Names
128 | Naoimhin
129 | Naomhan
130 | Neil
131 | Neville
132 | Nevin
133 | Niadh
134 | Niall
135 | Nolan
136 | Nuallan
137 | O'Boyle
138 | O'Brien
139 | O'Byrne
140 | O'Donnell
141 | O'Hannagain
142 | O'Hannigain
143 | O'Keefe
144 | O'Mooney
145 | O'Neal
146 | O'Boyle
147 | O'Bree
148 | O'Brian
149 | O'Brien
150 | O'Callaghann
151 | O'Connell
152 | O'Connor
153 | O'Dell
154 | O'Doherty
155 | O'Donnell
156 | O'Donoghue
157 | O'Dowd
158 | O'Driscoll
159 | O'Gorman
160 | O'Grady
161 | O'Hagan
162 | O'Halloran
163 | O'Hanlon
164 | O'Hara
165 | O'Hare
166 | O'Kane
167 | O'Keefe
168 | O'Keeffe
169 | O'Kelly
170 | O'Leary
171 | O'Loughlin
172 | O'Mahoney
173 | O'Mahony
174 | O'Malley
175 | O'Meara
176 | O'Neal
177 | O'Neill
178 | O'Reilly
179 | O'Rourke
180 | O'Ryan
181 | O'Shea
182 | O'Sullivan
183 | O'Toole
184 | Patrick
185 | Peatain
186 | Pharlain
187 | Power
188 | Quigley
189 | Quinn
190 | Quirke
191 | Raghailligh
192 | Reagan
193 | Register
194 | Reilly
195 | Reynold
196 | Rhys
197 | Riagain
198 | Riagan
199 | Riain
200 | Rian
201 | Rinn
202 | Roach
203 | Rodagh
204 | Rory
205 | Ruadh
206 | Ruadhain
207 | Ruadhan
208 | Ruaidh
209 | Samuel
210 | Scolaidhe
211 | Seaghdha
212 | Sechnall
213 | Seighin
214 | Shannon
215 | Sheehy
216 | Simon
217 | Sioda
218 | Sloan
219 | Sluaghadhan
220 | Suaird
221 | Sullivan
222 | Tadhg
223 | Tadhgan
224 | Taidhg
225 | Teagan
226 | Teague
227 | Tighearnach
228 | Tracey
229 | Treasach
230 | Whalen
231 | Whelan
232 | William
233 |
--------------------------------------------------------------------------------
/2-neural-nets/two_layer_sigmoidal_net.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import random
3 |
4 | from softmax import softmax
5 | from sigmoid import sigmoid, sigmoid_grad
6 | from gradient_checker import gradcheck_naive
7 |
8 | def forward_backward_prop(data, labels, params, dimensions):
9 | """
10 | Forward and backward propagation for a two-layer sigmoidal network
11 |
12 | Compute the forward propagation and for the cross entropy cost,
13 | and backward propagation for the gradients for all parameters.
14 | """
15 |
16 | ### Unpack network parameters (do not modify)
17 | ofs = 0
18 | Dx, H, Dy = (dimensions[0], dimensions[1], dimensions[2])
19 |
20 | # First layer weights
21 | W1 = np.reshape(params[ofs:ofs+ Dx * H], (Dx, H))
22 | ofs += Dx * H
23 | # First layer bias
24 | b1 = np.reshape(params[ofs:ofs + H], (1, H))
25 | ofs += H
26 |
27 | # Second layer weights
28 | W2 = np.reshape(params[ofs:ofs + H * Dy], (H, Dy))
29 | ofs += H * Dy
30 | # Second layer bias
31 | b2 = np.reshape(params[ofs:ofs + Dy], (1, Dy))
32 |
33 | activations_1 = sigmoid(np.dot(data, W1) + b1)
34 | activations_2 = softmax(activations_1 @ W2 + b2)
35 |
36 | cost = -np.sum(np.log(np.max(activations_2 * labels, axis=1)))
37 | print(cost)
38 |
39 | # ???
40 | gradW1 = 0
41 | gradb1 = 0
42 | gradW2 = 0
43 | gradb2 = 0
44 |
45 | assert gradb2.shape == b2.shape
46 | assert gradW2.shape == W2.shape
47 | assert gradb1.shape == b1.shape
48 | assert gradW1.shape == W1.shape
49 |
50 | ### Stack gradients (do not modify)
51 | grad = np.concatenate((gradW1.flatten(), gradb1.flatten(),
52 | gradW2.flatten(), gradb2.flatten()))
53 |
54 | return cost, grad
55 |
56 | def sanity_check():
57 | """
58 | Set up fake data and parameters for the neural network, and test using
59 | gradcheck.
60 | """
61 | print("Running sanity check...")
62 |
63 | N = 20 # number of data points
64 | dimensions = [10, 5, 10] # first element becomes dimensionality of each datum
65 | data = np.random.randn(N, dimensions[0]) # each row will be a datum
66 | # print(data) # will be 20 rows of 10 columsn. 20 datums, each 10d.
67 |
68 | # --- ---
69 | labels = np.zeros((N, dimensions[2])) # Create a matrix of size 20 x 10. These are one-hot encoded labels for each datum.
70 | for i in np.arange(N):
71 | labels[i,random.randint(0,dimensions[2]-1)] = 1
72 |
73 | # This line makes no frickin sense to me. 115 random numbers? For what? Just random.randn(115)
74 | # Could this be randomly initialized weights and biases?
75 | params = np.random.randn((dimensions[0] + 1) * dimensions[1] + (dimensions[1] + 1) * dimensions[2], )
76 | print(params)
77 |
78 | # This is going to take the gradient for the params, check that it makes sense.
79 | # forward_backward_prop returns cost and a gradient for any params.
80 | # So pass it any params (as above), and check that backward prop computed numerically (passing values really close to param, taking slope manually) matches what backprop has computed. Will only be correct if all the components of forward_backward_prop are working properly.
81 | gradcheck_naive(lambda params: forward_backward_prop(data, labels, params, dimensions), params)
82 |
83 | if __name__ == "__main__":
84 | sanity_check()
85 |
--------------------------------------------------------------------------------
/3-rnns/data/names/French.txt:
--------------------------------------------------------------------------------
1 | Abel
2 | Abraham
3 | Adam
4 | Albert
5 | Allard
6 | Archambault
7 | Armistead
8 | Arthur
9 | Augustin
10 | Babineaux
11 | Baudin
12 | Beauchene
13 | Beaulieu
14 | Beaumont
15 | Bélanger
16 | Bellamy
17 | Bellerose
18 | Belrose
19 | Berger
20 | Béringer
21 | Bernard
22 | Bertrand
23 | Bisset
24 | Bissette
25 | Blaise
26 | Blanc
27 | Blanchet
28 | Blanchett
29 | Bonfils
30 | Bonheur
31 | Bonhomme
32 | Bonnaire
33 | Bonnay
34 | Bonner
35 | Bonnet
36 | Borde
37 | Bordelon
38 | Bouchard
39 | Boucher
40 | Brisbois
41 | Brodeur
42 | Bureau
43 | Caron
44 | Cavey
45 | Chaput
46 | Charbonneau
47 | Charpentier
48 | Charron
49 | Chastain
50 | Chevalier
51 | Chevrolet
52 | Cloutier
53 | Colbert
54 | Comtois
55 | Cornett
56 | Coté
57 | Coupe
58 | Courtemanche
59 | Cousineau
60 | Couture
61 | Daniau
62 | D'aramitz
63 | Daviau
64 | David
65 | Deforest
66 | Degarmo
67 | Delacroix
68 | De la fontaine
69 | Deniau
70 | Deniaud
71 | Deniel
72 | Denis
73 | De sauveterre
74 | Deschamps
75 | Descoteaux
76 | Desjardins
77 | Desrochers
78 | Desrosiers
79 | Dubois
80 | Duchamps
81 | Dufort
82 | Dufour
83 | Duguay
84 | Dupond
85 | Dupont
86 | Durand
87 | Durant
88 | Duval
89 | Émile
90 | Eustis
91 | Fabian
92 | Fabre
93 | Fabron
94 | Faucher
95 | Faucheux
96 | Faure
97 | Favager
98 | Favre
99 | Favreau
100 | Fay
101 | Félix
102 | Firmin
103 | Fontaine
104 | Forest
105 | Forestier
106 | Fortier
107 | Foss
108 | Fournier
109 | Gage
110 | Gagne
111 | Gagnier
112 | Gagnon
113 | Garcon
114 | Gardinier
115 | Germain
116 | Géroux
117 | Giles
118 | Girard
119 | Giroux
120 | Glaisyer
121 | Gosse
122 | Gosselin
123 | Granger
124 | Guérin
125 | Guillory
126 | Hardy
127 | Harman
128 | Hébert
129 | Herbert
130 | Herriot
131 | Jacques
132 | Janvier
133 | Jordan
134 | Joubert
135 | Labelle
136 | Lachance
137 | Lachapelle
138 | Lamar
139 | Lambert
140 | Lane
141 | Langlais
142 | Langlois
143 | Lapointe
144 | Larue
145 | Laurent
146 | Lavigne
147 | Lavoie
148 | Leandres
149 | Lebeau
150 | Leblanc
151 | Leclair
152 | Leclerc
153 | Lécuyer
154 | Lefebvre
155 | Lefévre
156 | Lefurgey
157 | Legrand
158 | Lemaire
159 | Lémieux
160 | Leon
161 | Leroy
162 | Lesauvage
163 | Lestrange
164 | Lévêque
165 | Lévesque
166 | Linville
167 | Lyon
168 | Lyon
169 | Maçon
170 | Marchand
171 | Marie
172 | Marion
173 | Martel
174 | Martel
175 | Martin
176 | Masson
177 | Masson
178 | Mathieu
179 | Mercier
180 | Merle
181 | Michaud
182 | Michel
183 | Monet
184 | Monette
185 | Montagne
186 | Moreau
187 | Moulin
188 | Mullins
189 | Noel
190 | Oliver
191 | Olivier
192 | Page
193 | Paget
194 | Palomer
195 | Pan
196 | Pape
197 | Paquet
198 | Paquet
199 | Parent
200 | Paris
201 | Parris
202 | Pascal
203 | Patenaude
204 | Paternoster
205 | Paul
206 | Pelletier
207 | Perrault
208 | Perreault
209 | Perrot
210 | Petit
211 | Pettigrew
212 | Pierre
213 | Plamondon
214 | Plourde
215 | Poingdestre
216 | Poirier
217 | Porcher
218 | Poulin
219 | Proulx
220 | Renaud
221 | Rey
222 | Reyer
223 | Richard
224 | Richelieu
225 | Robert
226 | Roche
227 | Rome
228 | Romilly
229 | Rose
230 | Rousseau
231 | Roux
232 | Roy
233 | Royer
234 | Salomon
235 | Salvage
236 | Samson
237 | Samuel
238 | Sargent
239 | Sarkozi
240 | Sarkozy
241 | Sartre
242 | Sault
243 | Sauvage
244 | Sauvageau
245 | Sauvageon
246 | Sauvageot
247 | Sauveterre
248 | Savatier
249 | Segal
250 | Sergeant
251 | Séverin
252 | Simon
253 | Solomon
254 | Soucy
255 | St martin
256 | St pierre
257 | Tailler
258 | Tasse
259 | Thayer
260 | Thibault
261 | Thomas
262 | Tobias
263 | Tolbert
264 | Traver
265 | Travere
266 | Travers
267 | Traverse
268 | Travert
269 | Tremblay
270 | Tremble
271 | Victor
272 | Victors
273 | Villeneuve
274 | Vincent
275 | Vipond
276 | Voclain
277 | Yount
278 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Spanish.txt:
--------------------------------------------------------------------------------
1 | Abana
2 | Abano
3 | Abarca
4 | Abaroa
5 | Abascal
6 | Abasolo
7 | Abel
8 | Abelló
9 | Aberquero
10 | Abreu
11 | Acosta
12 | Agramunt
13 | Aiza
14 | Alamilla
15 | Albert
16 | Albuquerque
17 | Aldana
18 | Alfaro
19 | Alvarado
20 | Álvarez
21 | Alves
22 | Amador
23 | Andreu
24 | Antúnez
25 | Aqua
26 | Aquino
27 | Araújo
28 | Araullo
29 | Araya
30 | Arce
31 | Arechavaleta
32 | Arena
33 | Aritza
34 | Armando
35 | Arreola
36 | Arriola
37 | Asis
38 | Asturias
39 | Avana
40 | Azarola
41 | Banderas
42 | Barros
43 | Basurto
44 | Bautista
45 | Bello
46 | Belmonte
47 | Bengochea
48 | Benitez
49 | Bermúdez
50 | Blanco
51 | Blanxart
52 | Bolívar
53 | Bonaventura
54 | Bosque
55 | Bustillo
56 | Busto
57 | Bustos
58 | Cabello
59 | Cabrera
60 | Campo
61 | Campos
62 | Capello
63 | Cardona
64 | Caro
65 | Casales
66 | Castell
67 | Castellano
68 | Castillion
69 | Castillo
70 | Castro
71 | Chavarría
72 | Chavez
73 | Colón
74 | Costa
75 | Crespo
76 | Cruz
77 | Cuéllar
78 | Cuevas
79 | D'cruz
80 | D'cruze
81 | De la cruz
82 | De la fuente
83 | Del bosque
84 | De leon
85 | Delgado
86 | Del olmo
87 | De santigo
88 | Díaz
89 | Dominguez
90 | Duarte
91 | Durante
92 | Echevarría
93 | Echeverría
94 | Elizondo
95 | Escamilla
96 | Escárcega
97 | Escarrà
98 | Esparza
99 | Espina
100 | Espino
101 | Espinosa
102 | Espinoza
103 | Estévez
104 | Etxebarria
105 | Etxeberria
106 | Félix
107 | Fernández
108 | Ferrer
109 | Fierro
110 | Flores
111 | Fonseca
112 | Franco
113 | Fuentes
114 | Gallego
115 | Gallo
116 | García
117 | Garrastazu
118 | Garza
119 | Gaspar
120 | Gebara
121 | Gomez
122 | Gonzales
123 | Gonzalez
124 | Grec
125 | Guadarrama
126 | Guerra
127 | Guerrero
128 | Gutiérrez
129 | Gutierrez
130 | Hernandez
131 | Herrera
132 | Herrero
133 | Hierro
134 | Holguín
135 | Huerta
136 | Ibáñez
137 | Ibarra
138 | Iñíguez
139 | Iturburua
140 | Jaso
141 | Jasso
142 | Jimenez
143 | Jordà
144 | Juárez
145 | Lobo
146 | Lopez
147 | Losa
148 | Loyola
149 | Machado
150 | Macías
151 | Maradona
152 | María
153 | Marino
154 | Márquez
155 | Martell
156 | Martí
157 | Martínez
158 | Martinez
159 | Mas
160 | Mata
161 | Mateu
162 | Medina
163 | Melendez
164 | Méndez
165 | Mendoza
166 | Menendez
167 | Merlo
168 | Michel
169 | Mingo
170 | Moles
171 | Molina
172 | Montero
173 | Morales
174 | Moralez
175 | Moreno
176 | Narváez
177 | Nieves
178 | Noguerra
179 | Núñez
180 | Obando
181 | Ochoa
182 | Ojeda
183 | Ola
184 | Oleastro
185 | Olguin
186 | Oliver
187 | Olmos
188 | Oquendo
189 | Orellana
190 | Oriol
191 | Ortega
192 | Ortiz
193 | Palomo
194 | Paredes
195 | Pavia
196 | Peláez
197 | Peña
198 | Pérez
199 | Perez
200 | Petit
201 | Picasso
202 | Porra
203 | Porras
204 | Prieto
205 | Puerta
206 | Puga
207 | Puig
208 | Quinones
209 | Quintana
210 | Quirós
211 | Ramírez
212 | Ramos
213 | Rana
214 | Rendón
215 | Rey
216 | Reyes
217 | Rios
218 | Rivera
219 | Rivero
220 | Robledo
221 | Robles
222 | Rocha
223 | Rodríguez
224 | Rodriquez
225 | Roig
226 | Rojas
227 | Rojo
228 | Roldán
229 | Romà
230 | Romà
231 | Romero
232 | Rosa
233 | Rosales
234 | Rubio
235 | Ruiz
236 | Sala
237 | Salamanca
238 | Salazar
239 | Salcedo
240 | Salinas
241 | Sanchez
242 | Sandoval
243 | San nicolas
244 | Santana
245 | Santiago
246 | Santillian
247 | Santos
248 | Sastre
249 | Sepúlveda
250 | Sierra
251 | Silva
252 | Soler
253 | Solo
254 | Solos
255 | Soto
256 | Suárez
257 | Suero
258 | Tapia
259 | Terrazas
260 | Tomàs
261 | Torres
262 | Tos
263 | Tosell
264 | Toset
265 | Travieso
266 | Trujillo
267 | Ubina
268 | Urbina
269 | Ureña
270 | Valdez
271 | Valencia
272 | Varela
273 | Vargas
274 | Vásquez
275 | Vázquez
276 | Vega
277 | Vela
278 | Vela
279 | Velazquez
280 | Ventura
281 | Vicario
282 | Vilaró
283 | Villa
284 | Villalobos
285 | Villanueva
286 | Villaverde
287 | Viola
288 | Viteri
289 | Vivas
290 | Vives
291 | Ybarra
292 | Zabala
293 | Zambrano
294 | Zamorano
295 | Zapatero
296 | Zavala
297 | Zubizarreta
298 | Zuñiga
299 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Dutch.txt:
--------------------------------------------------------------------------------
1 | Aalsburg
2 | Aalst
3 | Aarle
4 | Achteren
5 | Achthoven
6 | Adrichem
7 | Aggelen
8 | Agteren
9 | Agthoven
10 | Akkeren
11 | Aller
12 | Alphen
13 | Alst
14 | Altena
15 | Althuis
16 | Amelsvoort
17 | Amersvoort
18 | Amstel
19 | Andel
20 | Andringa
21 | Ankeren
22 | Antwerp
23 | Antwerpen
24 | Apeldoorn
25 | Arendonk
26 | Asch
27 | Assen
28 | Baarle
29 | Bokhoven
30 | Breda
31 | Bueren
32 | Buggenum
33 | Buiren
34 | Buren
35 | Can
36 | Cann
37 | Canne
38 | Daal
39 | Daalen
40 | Dael
41 | Daele
42 | Dale
43 | Dalen
44 | Laar
45 | Vliert
46 | Akker
47 | Andel
48 | Denend
49 | Aart
50 | Beek
51 | Berg
52 | Hout
53 | Laar
54 | See
55 | Stoep
56 | Veen
57 | Ven
58 | Venn
59 | Venne
60 | Vennen
61 | Zee
62 | Donk
63 | Haanraads
64 | Haanraats
65 | Haanrade
66 | Haanrath
67 | Haenraats
68 | Haenraets
69 | Hanraets
70 | Hassel
71 | Hautem
72 | Hautum
73 | Heel
74 | Herten
75 | Hofwegen
76 | Horn
77 | Hout
78 | Houte
79 | Houtem
80 | Houten
81 | Houttum
82 | Houtum
83 | Kan
84 | Kann
85 | Kanne
86 | Kappel
87 | Karl
88 | Kikkert
89 | Klein
90 | Klerk
91 | Klerken
92 | Klerks
93 | Klerkse
94 | Klerkx
95 | Klerx
96 | Kloet
97 | Kloeten
98 | Kloeter
99 | Koeman
100 | Koemans
101 | Kolen
102 | Kolijn
103 | Kollen
104 | Koning
105 | Kool
106 | Koole
107 | Koolen
108 | Kools
109 | Kouman
110 | Koumans
111 | Krantz
112 | Kranz
113 | Krusen
114 | Kuijpers
115 | Kuiper
116 | Kuipers
117 | Laar
118 | Langbroek
119 | Laren
120 | Lauwens
121 | Lauwers
122 | Leeuwenhoeck
123 | Leeuwenhoek
124 | Leeuwenhoek
125 | Lucas
126 | Lucassen
127 | Lyon
128 | Maas
129 | Maes
130 | Maessen
131 | Marquering
132 | Marqueringh
133 | Marquerink
134 | Mas
135 | Meeuwe
136 | Meeuwes
137 | Meeuwessen
138 | Meeuweszen
139 | Meeuwis
140 | Meeuwissen
141 | Meeuwsen
142 | Meisner
143 | Merckx
144 | Mertens
145 | Michel
146 | Middelburg
147 | Middlesworth
148 | Mohren
149 | Mooren
150 | Mulder
151 | Muyskens
152 | Nagel
153 | Nelissen
154 | Nifterick
155 | Nifterick
156 | Nifterik
157 | Nifterik
158 | Niftrik
159 | Niftrik
160 | Offermans
161 | Ogterop
162 | Ogtrop
163 | Oirschot
164 | Oirschotten
165 | Oomen
166 | Oorschot
167 | Oorschot
168 | Ophoven
169 | Otten
170 | Pander
171 | Panders
172 | Paulis
173 | Paulissen
174 | Peerenboom
175 | Peeters
176 | Peij
177 | Pender
178 | Penders
179 | Pennders
180 | Penner
181 | Penners
182 | Peter
183 | Peusen
184 | Pey
185 | Philips
186 | Prinsen
187 | Rademaker
188 | Rademakers
189 | Ramaaker
190 | Ramaker
191 | Ramakers
192 | Ramecker
193 | Rameckers
194 | Raske
195 | Reijnder
196 | Reijnders
197 | Reinder
198 | Reinders
199 | Reynder
200 | Reynders
201 | Richard
202 | Rietveld
203 | Rijnder
204 | Rijnders
205 | Robert
206 | Roggeveen
207 | Roijacker
208 | Roijackers
209 | Roijakker
210 | Roijakkers
211 | Romeijn
212 | Romeijnders
213 | Romeijnsen
214 | Romijn
215 | Romijnders
216 | Romijnsen
217 | Rompa
218 | Rompa
219 | Rompaeij
220 | Rompaey
221 | Rompaij
222 | Rompay
223 | Rompaye
224 | Rompu
225 | Rompuy
226 | Rooiakker
227 | Rooiakkers
228 | Rooijakker
229 | Rooijakkers
230 | Roosa
231 | Roosevelt
232 | Rossem
233 | Rossum
234 | Rumpade
235 | Rutten
236 | Ryskamp
237 | Samson
238 | Sanna
239 | Schenck
240 | Schermer
241 | Schneider
242 | Schneiders
243 | Schneijder
244 | Schneijders
245 | Schoonenburg
246 | Schoonraad
247 | Schoorel
248 | Schoorel
249 | Schoorl
250 | Schorel
251 | Schrijnemakers
252 | Schuyler
253 | Schwarzenberg
254 | Seeger
255 | Seegers
256 | Seelen
257 | Segers
258 | Segher
259 | Seghers
260 | Severijns
261 | Severins
262 | Sevriens
263 | Silje
264 | Simon
265 | Simonis
266 | Slootmaekers
267 | Smeets
268 | Smets
269 | Smit
270 | Smits
271 | Snaaijer
272 | Snaijer
273 | Sneiders
274 | Sneijder
275 | Sneijders
276 | Sneijer
277 | Sneijers
278 | Snell
279 | Snider
280 | Sniders
281 | Snijder
282 | Snijders
283 | Snyder
284 | Snyders
285 | Specht
286 | Spijker
287 | Spiker
288 | Ter Avest
289 | Teunissen
290 | Theunissen
291 | Tholberg
292 | Tillens
293 | Tunison
294 | Tunneson
295 | Vandale
296 | Vandroogenbroeck
297 | Vann
298 |
--------------------------------------------------------------------------------
/simplest-gan/gan.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import matplotlib.pyplot as plt
3 | from torch import Tensor, nn
4 | from torch.autograd import Variable
5 | import torch.nn.functional as F
6 | import torch
7 |
8 | actual_dist_mean = 3
9 | actual_dist_stddev = 2
10 | num_samples = 1000
11 |
12 | sample_real_dist = lambda: Variable(Tensor(np.random.normal(actual_dist_mean, actual_dist_stddev, num_samples)))
13 | sample_fake_data = lambda: Variable(Tensor(np.random.rand(num_samples)))
14 |
15 |
16 | class Generator(nn.Module):
17 | """
18 | Transforms a weird distribution into one that is likely to fool the Discriminator.
19 | """
20 | def __init__(self, input_size, hidden_size, output_size):
21 | super().__init__()
22 | self.linear1 = nn.Linear(input_size, hidden_size)
23 | self.linear2 = nn.Linear(hidden_size, hidden_size)
24 | self.linear3 = nn.Linear(hidden_size, output_size)
25 |
26 | def forward(self, x):
27 | x = F.elu(self.linear1(x))
28 | x = F.elu(self.linear2(x))
29 | return self.linear3(x)
30 |
31 |
32 | class Discriminator(nn.Module):
33 | """
34 | Tries to tell the difference between the real distribution, and a fake distribution output by the Generator network.
35 | """
36 | def __init__(self, input_size, hidden_size, output_size):
37 | super().__init__()
38 | self.linear1 = nn.Linear(input_size, hidden_size)
39 | self.linear2 = nn.Linear(hidden_size, hidden_size)
40 | self.linear3 = nn.Linear(hidden_size, output_size)
41 |
42 | def forward(self, x):
43 | x = F.elu(self.linear1(x))
44 | x = F.elu(self.linear2(x))
45 | return F.sigmoid(self.linear3(x))
46 |
47 | hidden_size = 32
48 | output_size = 1 # 0 is fake dist, 1 is real dist
49 |
50 | G = Generator(num_samples, hidden_size, num_samples) # notice that num_samples is the output, because the generator's output is a sample for the discriminator
51 | D = Discriminator(num_samples, hidden_size, 1)
52 |
53 |
54 | num_epochs = 25000
55 | print_interval = 500
56 | g_steps = 1
57 | d_steps = 1 # apparently you can do more d steps than g steps if you want
58 | criterion = nn.BCELoss()
59 | g_optimizer = torch.optim.Adam(G.parameters())
60 | d_optimizer = torch.optim.Adam(D.parameters())
61 |
62 | true_label = Variable(torch.ones(1))
63 | false_label = Variable(torch.zeros(1))
64 |
65 | for epoch in range(num_epochs):
66 |
67 | for d_step in range(d_steps):
68 | D.zero_grad()
69 | # Discriminator gets trained with real data, labeled correctly...
70 | real_data = sample_real_dist()
71 | real_outputs = D(real_data)
72 | true_real_loss = criterion(real_outputs, true_label)
73 | true_real_loss.backward()
74 |
75 | # and fake data, labeled correctly...
76 | fake_inputs = G(sample_fake_data())
77 | fake_outputs = D(fake_inputs)
78 | false_fake_loss = criterion(fake_outputs, false_label)
79 | false_fake_loss.backward()
80 | d_optimizer.step()
81 |
82 | for g_step in range(g_steps):
83 | G.zero_grad()
84 | # And then we train the generator by passing its outputs and _incorrect_ labels to the discriminator.
85 | fake_inputs = G(sample_fake_data())
86 | fake_outputs = D(fake_inputs)
87 | true_fake_loss = criterion(fake_outputs, true_label) # confusing!
88 | true_fake_loss.backward()
89 | g_optimizer.step()
90 |
91 | if epoch % print_interval == 0:
92 | dist = fake_inputs.data.numpy()
93 | print("{}: D loss: {:.2f}/{:.2f}\tG loss: {:.2f}\tG μ: {:.2f} (real: {})\tG σ: {:.2f} (real: {})".format(
94 | epoch,
95 | true_real_loss.data[0],
96 | false_fake_loss.data[0],
97 | true_fake_loss.data[0],
98 | np.mean(dist),
99 | actual_dist_mean,
100 | np.std(dist),
101 | actual_dist_stddev
102 | ))
103 |
--------------------------------------------------------------------------------
/3-rnns/rnn.py:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 |
3 | import torch
4 | from torch import nn
5 | import glob
6 | import unicodedata
7 | import string
8 | import numpy as np
9 | from torch.autograd import Variable
10 | import itertools
11 | import sys
12 |
13 | def findFiles(path): return glob.glob(path)
14 |
15 | all_letters = string.ascii_letters + ',.; \''
16 |
17 | # Turn a Unicode string to plain ASCII, thanks to http://stackoverflow.com/a/518232/2809427
18 | def unicodeToAscii(s):
19 | return ''.join(
20 | c for c in unicodedata.normalize('NFD', s)
21 | if unicodedata.category(c) != 'Mn'
22 | and c in all_letters
23 | )
24 |
25 | language_to_names = {}
26 | for file in findFiles('data/names/*.txt'):
27 | with open(file) as infile:
28 | language = file.split('/')[-1].replace('.txt', '')
29 | language_to_names[language] = [unicodeToAscii(x.strip()) for x in infile.readlines()]
30 |
31 | HIDDEN_DIM = 128
32 | CHAR_DIM = len(all_letters)
33 | LANGUAGE_DIM = len(language_to_names)
34 | COMBINATION_DIM = CHAR_DIM + HIDDEN_DIM
35 |
36 | _tensor_index_by_char = {}
37 | _char_by_tensor_index = {}
38 | for i, c in enumerate(all_letters):
39 | _tensor_index_by_char[c] = i
40 | _char_by_tensor_index[i] = c
41 | _char_tensors_by_index = np.identity(CHAR_DIM)
42 |
43 | def char_to_tensor(c):
44 | return _char_tensors_by_index[_tensor_index_by_char[c]]
45 |
46 | def name_to_tensor(name):
47 | return torch.Tensor([char_to_tensor(c) for c in name])
48 |
49 | _language_tensors_by_index = np.identity(LANGUAGE_DIM)
50 |
51 | language_list = list(language_to_names.keys())
52 |
53 | _tensor_index_by_language = {}
54 | _language_by_tensor_index = {}
55 | for i, language in enumerate(language_list):
56 | _tensor_index_by_language[language] = i
57 | _language_by_tensor_index[i] = language
58 |
59 | def language_to_tensor(language):
60 | return torch.Tensor(_language_tensors_by_index[_tensor_index_by_language[language]])
61 |
62 | def tensor_to_language(x):
63 | return asdflkjdsfdas
64 |
65 |
66 | class RNN(nn.Module):
67 | def __init__(self):
68 | super().__init__()
69 | self.input_to_output = nn.Linear(COMBINATION_DIM, LANGUAGE_DIM)
70 | self.input_to_hidden = nn.Linear(COMBINATION_DIM, HIDDEN_DIM)
71 | self.log_softmax = nn.LogSoftmax()
72 | self.zero()
73 |
74 | def forward(self, input, hidden):
75 | combination = torch.cat((input, hidden))
76 | output = self.input_to_output(combination.t())
77 | new_hidden = self.input_to_hidden(combination.t()).t()
78 | transformed_output = self.log_softmax(output)
79 | return transformed_output, new_hidden
80 |
81 | def zero(self):
82 | self._zero_grad()
83 | self._zero_hidden()
84 |
85 | def _zero_grad(self):
86 | self.input_to_output.zero_grad()
87 | self.input_to_hidden.zero_grad()
88 | self.log_softmax.zero_grad()
89 |
90 | def _zero_hidden(self):
91 | self.hidden = Variable(torch.zeros(HIDDEN_DIM, 1))
92 |
93 | def flatten(iterable):
94 | return list(itertools.chain(*iterable))
95 |
96 | _train_pairs = flatten([list(zip(len(names) * [language], names) )for language, names in language_to_names.items()])
97 | all_training_examples = [(_tensor_index_by_language[x], name_to_tensor(y)) for (x, y) in _train_pairs]
98 |
99 | def train(num_iters=100000, print_iters=5000, learning_rate=0.01):
100 | rnn = RNN()
101 | loss_function = nn.NLLLoss()
102 | for i in range(num_iters):
103 | for label, name in all_training_examples:
104 | rnn.zero()
105 | for c in name:
106 | out, hidden = rnn(Variable(c.unsqueeze(1)), hidden)
107 | loss_result = loss_function(out, Variable(torch.LongTensor([label])))
108 | loss_result.backward(retain_graph=True)
109 | for param in rnn.parameters():
110 | param.data -= param.grad.data * learning_rate
111 | loss = loss_result.data[0]
112 | print("{}: {}".format(i, loss))
113 | if loss < 1e-6:
114 | sys.exit(0)
115 |
116 | train()
117 |
--------------------------------------------------------------------------------
/simplest-gan/README.md:
--------------------------------------------------------------------------------
1 | ### Results:
2 |
3 | There's a ton of randomness, but it's approximately converging on the correct values of the distribution.
4 |
5 | Thanks to `devnag` for the [tutorial](https://medium.com/@devnag/generative-adversarial-networks-gans-in-50-lines-of-code-pytorch-e81b79659e3f).
6 |
7 | ```
8 | 0: D loss: 0.53/0.69 G loss: 0.71 G μ: 0.00 (real: 3) G σ: 0.16 (real: 2)
9 | 500: D loss: 0.11/0.09 G loss: 2.52 G μ: 0.94 (real: 3) G σ: 0.68 (real: 2)
10 | 1000: D loss: 2.58/0.71 G loss: 1.98 G μ: 0.98 (real: 3) G σ: 0.84 (real: 2)
11 | 1500: D loss: 0.91/0.34 G loss: 1.96 G μ: 3.05 (real: 3) G σ: 1.72 (real: 2)
12 | 2000: D loss: 0.07/0.79 G loss: 0.83 G μ: 3.32 (real: 3) G σ: 1.71 (real: 2)
13 | 2500: D loss: 0.91/0.35 G loss: 1.90 G μ: 4.60 (real: 3) G σ: 1.75 (real: 2)
14 | 3000: D loss: 0.37/0.61 G loss: 1.40 G μ: 2.61 (real: 3) G σ: 1.33 (real: 2)
15 | 3500: D loss: 0.29/1.10 G loss: 0.58 G μ: 2.13 (real: 3) G σ: 1.19 (real: 2)
16 | 4000: D loss: 2.11/0.85 G loss: 0.63 G μ: 2.67 (real: 3) G σ: 1.11 (real: 2)
17 | 4500: D loss: 0.07/0.18 G loss: 1.87 G μ: 2.28 (real: 3) G σ: 1.26 (real: 2)
18 | 5000: D loss: 0.76/0.40 G loss: 1.20 G μ: 3.71 (real: 3) G σ: 1.07 (real: 2)
19 | 5500: D loss: 0.23/0.01 G loss: 5.00 G μ: 2.27 (real: 3) G σ: 3.82 (real: 2)
20 | 6000: D loss: 0.84/0.20 G loss: 2.37 G μ: 6.61 (real: 3) G σ: 2.82 (real: 2)
21 | 6500: D loss: 0.62/0.31 G loss: 1.41 G μ: 2.93 (real: 3) G σ: 1.30 (real: 2)
22 | 7000: D loss: 1.13/0.90 G loss: 0.67 G μ: 2.62 (real: 3) G σ: 1.24 (real: 2)
23 | 7500: D loss: 0.50/0.19 G loss: 2.45 G μ: 3.13 (real: 3) G σ: 1.41 (real: 2)
24 | 8000: D loss: 2.20/0.85 G loss: 0.61 G μ: 3.01 (real: 3) G σ: 1.37 (real: 2)
25 | 8500: D loss: 0.85/0.38 G loss: 1.52 G μ: 3.15 (real: 3) G σ: 1.36 (real: 2)
26 | 9000: D loss: 0.93/0.50 G loss: 1.15 G μ: 3.65 (real: 3) G σ: 1.38 (real: 2)
27 | 9500: D loss: 0.28/0.33 G loss: 1.33 G μ: 2.87 (real: 3) G σ: 1.42 (real: 2)
28 | 10000: D loss: 4.83/0.49 G loss: 1.23 G μ: 2.32 (real: 3) G σ: 1.87 (real: 2)
29 | 10500: D loss: 0.11/0.81 G loss: 0.79 G μ: 2.89 (real: 3) G σ: 1.08 (real: 2)
30 | 11000: D loss: 0.59/0.17 G loss: 1.89 G μ: 2.31 (real: 3) G σ: 1.41 (real: 2)
31 | 11500: D loss: 0.24/0.22 G loss: 2.02 G μ: 4.05 (real: 3) G σ: 1.84 (real: 2)
32 | 12000: D loss: 0.39/0.02 G loss: 5.12 G μ: 4.04 (real: 3) G σ: 1.81 (real: 2)
33 | 12500: D loss: 1.44/1.13 G loss: 0.67 G μ: 3.29 (real: 3) G σ: 1.37 (real: 2)
34 | 13000: D loss: 0.16/0.33 G loss: 1.60 G μ: 3.46 (real: 3) G σ: 1.63 (real: 2)
35 | 13500: D loss: 0.06/0.19 G loss: 2.21 G μ: 3.18 (real: 3) G σ: 1.63 (real: 2)
36 | 14000: D loss: 0.70/0.80 G loss: 0.71 G μ: 2.43 (real: 3) G σ: 1.19 (real: 2)
37 | 14500: D loss: 1.48/0.18 G loss: 2.64 G μ: 5.03 (real: 3) G σ: 2.59 (real: 2)
38 | 15000: D loss: 1.93/1.08 G loss: 4.77 G μ: 4.84 (real: 3) G σ: 2.95 (real: 2)
39 | 15500: D loss: 0.36/0.91 G loss: 2.76 G μ: 2.90 (real: 3) G σ: 1.96 (real: 2)
40 | 16000: D loss: 3.04/0.42 G loss: 1.62 G μ: 4.00 (real: 3) G σ: 1.87 (real: 2)
41 | 16500: D loss: 1.87/0.74 G loss: 0.50 G μ: 2.79 (real: 3) G σ: 1.97 (real: 2)
42 | 17000: D loss: 1.16/0.51 G loss: 1.15 G μ: 3.09 (real: 3) G σ: 2.30 (real: 2)
43 | 17500: D loss: 0.17/0.25 G loss: 2.88 G μ: 2.99 (real: 3) G σ: 2.08 (real: 2)
44 | 18000: D loss: 0.07/0.20 G loss: 3.01 G μ: 2.47 (real: 3) G σ: 2.04 (real: 2)
45 | 18500: D loss: 0.18/0.85 G loss: 1.23 G μ: 2.43 (real: 3) G σ: 2.01 (real: 2)
46 | 19000: D loss: 0.03/0.46 G loss: 1.29 G μ: 2.50 (real: 3) G σ: 2.08 (real: 2)
47 | 19500: D loss: 0.44/0.04 G loss: 3.67 G μ: 2.20 (real: 3) G σ: 1.76 (real: 2)
48 | 20000: D loss: 0.02/0.09 G loss: 3.46 G μ: 2.64 (real: 3) G σ: 2.26 (real: 2)
49 | 20500: D loss: 0.01/0.25 G loss: 1.63 G μ: 1.03 (real: 3) G σ: 1.91 (real: 2)
50 | 21000: D loss: 0.00/0.00 G loss: 7.32 G μ: 2.81 (real: 3) G σ: 4.17 (real: 2)
51 | 21500: D loss: 0.30/0.43 G loss: 1.71 G μ: 3.19 (real: 3) G σ: 2.86 (real: 2)
52 | 22000: D loss: 0.08/0.18 G loss: 4.18 G μ: 2.50 (real: 3) G σ: 1.70 (real: 2)
53 | 22500: D loss: 3.30/0.23 G loss: 1.57 G μ: 2.19 (real: 3) G σ: 1.70 (real: 2)
54 | 23000: D loss: 8.86/0.54 G loss: 3.56 G μ: 3.61 (real: 3) G σ: 2.40 (real: 2)
55 | 23500: D loss: 0.00/0.60 G loss: 1.02 G μ: 2.38 (real: 3) G σ: 2.02 (real: 2)
56 | 24000: D loss: 0.46/0.32 G loss: 2.38 G μ: 4.87 (real: 3) G σ: 3.21 (real: 2)
57 | 24500: D loss: 0.01/0.10 G loss: 3.01 G μ: 3.72 (real: 3) G σ: 2.36 (real: 2)
58 | ```
59 |
--------------------------------------------------------------------------------
/4-cnns/cnn.py:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 |
3 | import torch
4 | import torch.nn as nn
5 | import torch.optim as optim
6 | from torch.optim import lr_scheduler
7 | import glob
8 | from torch.autograd import Variable
9 | import numpy as np
10 | import torchvision
11 | from torchvision import datasets, models
12 | from torchvision import transforms as t
13 | import matplotlib.pyplot as plt
14 | import time
15 | import os
16 |
17 | plt.ion() # interactive mode
18 |
19 |
20 | DATA_PATH = "/home/jbenn/data/hymenoptera/"
21 | PHASES = ['train', 'val']
22 | MEAN_TRANSFORM = np.array([0.485, 0.456, 0.406])
23 | STD_TRANSFORM = np.array([0.229, 0.224, 0.225])
24 | BATCH_SIZE = 4
25 |
26 | transforms = {
27 | 'train': t.Compose([
28 | t.RandomSizedCrop(224),
29 | t.RandomHorizontalFlip(),
30 | t.ToTensor(),
31 | # t.Normalize(MEAN_TRANSFORM, STD_TRANSFORM)
32 | ]),
33 | 'val': t.Compose([
34 | t.Scale(256),
35 | t.CenterCrop(224),
36 | t.ToTensor(),
37 | # t.Normalize(MEAN_TRANSFORM, STD_TRANSFORM)
38 | ])
39 | }
40 |
41 | image_folders = {
42 | phase: datasets.ImageFolder(DATA_PATH + phase, transforms[phase])
43 | for phase in PHASES
44 | }
45 |
46 | class_names = image_folders['val'].classes
47 |
48 | dataloaders = { phase: torch.utils.data.DataLoader(
49 | dataset=image_folders[phase],
50 | batch_size=BATCH_SIZE,
51 | shuffle=True,
52 | num_workers=4
53 | ) for phase in PHASES }
54 |
55 |
56 | def imshow(inp):
57 | # inp = inp.numpy().transpose((1, 2, 0))
58 | # mean = np.array([0.485, 0.456, 0.406])
59 | # std = np.array([0.229, 0.224, 0.225])
60 | # inp = std * inp + mean
61 | plt.imshow((inp * 255).numpy().transpose(1, 2, 0).astype("uint8"))
62 | # print(inp * 255)
63 | # if title is not None:
64 | # plt.title(title)
65 | # plt.pause(0.001) # pause a bit so that plots are updated
66 |
67 | # inputs, classes = next(iter(dataloaders['train']))
68 | # grid = torchvision.utils.make_grid(inputs)
69 | # ValueError: Floating point image RGB values must be in the 0..1 range.
70 | # imshow(grid, title=[class_names[x] for x in classes])
71 | imshow(inputs[0])
72 |
73 |
74 | dataset_sizes = { phase: len(image_folders[phase]) for phase in PHASES }
75 |
76 | def train(model, criterion, optimizer, num_epochs):
77 | losses = {}
78 | loss_history = { 'train': [], 'val': [] }
79 |
80 | for epoch in range(num_epochs):
81 | for phase in PHASES:
82 | losses[phase] = 0
83 | if phase == 'train':
84 | model.train()
85 | elif phase == 'val':
86 | model.eval()
87 |
88 | for inputs, classes in dataloaders[phase]:
89 | inputs = Variable(inputs.cuda(1))
90 | classes = Variable(classes.cuda(1))
91 |
92 | optimizer.zero_grad()
93 | outputs = model(inputs)
94 | predictions, prediction_indexes = torch.max(outputs.data, 1)
95 |
96 | loss = criterion(outputs, classes)
97 |
98 | losses[phase] += loss.data[0] / dataset_sizes[phase]
99 | loss_history[phase].append(loss.data[0])
100 |
101 | if phase == 'train':
102 | loss.backward()
103 | optimizer.step()
104 |
105 | print("epoch {}\t train: {:.4f}\t val: {:.4f}".format(epoch, losses['train'], losses['val']))
106 |
107 | torch.save(model.state_dict(), "last_weights")
108 | return loss_history
109 |
110 |
111 | CONV_STRIDE = 3
112 |
113 | class VGGish(nn.Module):
114 | def __init__(self):
115 | super().__init__()
116 | self.layer1 = nn.Sequential(
117 | nn.Conv2d(3, 64, CONV_STRIDE, padding=1),
118 | nn.BatchNorm2d(64),
119 | nn.ReLU(),
120 | nn.Conv2d(64, 64, CONV_STRIDE, padding=1),
121 | nn.ReLU()
122 | )
123 | self.layer2 = nn.Sequential(
124 | nn.MaxPool2d(2),
125 | nn.Conv2d(64, 128, CONV_STRIDE, padding=1),
126 | nn.BatchNorm2d(128),
127 | nn.ReLU(),
128 | nn.Conv2d(128, 128, CONV_STRIDE, padding=1),
129 | nn.BatchNorm2d(128),
130 | nn.ReLU()
131 | )
132 | self.layer3 = nn.Sequential(
133 | nn.MaxPool2d(2),
134 | nn.Conv2d(128, 256, CONV_STRIDE, padding=1),
135 | nn.BatchNorm2d(256),
136 | nn.ReLU(),
137 | nn.Conv2d(256, 256, CONV_STRIDE, padding=1),
138 | nn.BatchNorm2d(256),
139 | nn.ReLU()
140 | )
141 | self.fc = nn.Linear(in_features=256*56*56, out_features=2)
142 | self.softmax = nn.Softmax()
143 |
144 | def forward(self, inp):
145 | out = self.layer1(inp)
146 | out = self.layer2(out)
147 | out = self.layer3(out)
148 | out = out.view(out.size(0), -1)
149 | out = self.fc(out)
150 | return self.softmax(out)
151 |
152 | model = VGGish().cuda(1)
153 | criterion = nn.CrossEntropyLoss()
154 | optimizer = optim.SGD(model.parameters(), lr=.01, momentum=0.9)
155 | loss_history = train(model, criterion, optimizer, num_epochs=5)
156 |
157 |
158 | # visualizer
159 | # enumerate val
160 | # wrap vals in var, cudafy
161 | # get predictions
162 | # plt.subplot
163 | # imshow
164 | plt.plot(loss_history['train'])
165 | plt.plot(loss_history['val'])
166 |
167 |
168 |
169 |
170 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/10-set-routines.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Set routines"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 4,
13 | "metadata": {
14 | "collapsed": true
15 | },
16 | "outputs": [],
17 | "source": [
18 | "import numpy as np"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 5,
24 | "metadata": {},
25 | "outputs": [
26 | {
27 | "data": {
28 | "text/plain": [
29 | "'1.11.2'"
30 | ]
31 | },
32 | "execution_count": 5,
33 | "metadata": {},
34 | "output_type": "execute_result"
35 | }
36 | ],
37 | "source": [
38 | "np.__version__"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": 6,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "author = 'kyubyong. longinglove@nate.com'"
48 | ]
49 | },
50 | {
51 | "cell_type": "markdown",
52 | "metadata": {},
53 | "source": [
54 | "## Making proper sets"
55 | ]
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "metadata": {},
60 | "source": [
61 | "Q1. Get unique elements and reconstruction indices from x. And reconstruct x."
62 | ]
63 | },
64 | {
65 | "cell_type": "code",
66 | "execution_count": 15,
67 | "metadata": {},
68 | "outputs": [
69 | {
70 | "name": "stdout",
71 | "output_type": "stream",
72 | "text": [
73 | "unique elements = [1 2 3 4 6]\n",
74 | "reconstruction indices = [0 1 4 3 1 2 1]\n",
75 | "reconstructed = [1 2 6 4 2 3 2]\n"
76 | ]
77 | }
78 | ],
79 | "source": [
80 | "x = np.array([1, 2, 6, 4, 2, 3, 2])\n",
81 | "\n"
82 | ]
83 | },
84 | {
85 | "cell_type": "markdown",
86 | "metadata": {},
87 | "source": [
88 | "## Boolean operations"
89 | ]
90 | },
91 | {
92 | "cell_type": "markdown",
93 | "metadata": {},
94 | "source": [
95 | "Q2. Create a boolean array of the same shape as x. If each element of x is present in y, the result will be True, otherwise False."
96 | ]
97 | },
98 | {
99 | "cell_type": "code",
100 | "execution_count": 19,
101 | "metadata": {},
102 | "outputs": [
103 | {
104 | "name": "stdout",
105 | "output_type": "stream",
106 | "text": [
107 | "[ True True False False True]\n"
108 | ]
109 | }
110 | ],
111 | "source": [
112 | "x = np.array([0, 1, 2, 5, 0])\n",
113 | "y = np.array([0, 1])\n"
114 | ]
115 | },
116 | {
117 | "cell_type": "markdown",
118 | "metadata": {},
119 | "source": [
120 | "Q3. Find the unique intersection of x and y."
121 | ]
122 | },
123 | {
124 | "cell_type": "code",
125 | "execution_count": 20,
126 | "metadata": {},
127 | "outputs": [
128 | {
129 | "name": "stdout",
130 | "output_type": "stream",
131 | "text": [
132 | "[0 1]\n"
133 | ]
134 | }
135 | ],
136 | "source": [
137 | "x = np.array([0, 1, 2, 5, 0])\n",
138 | "y = np.array([0, 1, 4])\n"
139 | ]
140 | },
141 | {
142 | "cell_type": "markdown",
143 | "metadata": {},
144 | "source": [
145 | "Q4. Find the unique elements of x that are not present in y."
146 | ]
147 | },
148 | {
149 | "cell_type": "code",
150 | "execution_count": 21,
151 | "metadata": {},
152 | "outputs": [
153 | {
154 | "name": "stdout",
155 | "output_type": "stream",
156 | "text": [
157 | "[2 5]\n"
158 | ]
159 | }
160 | ],
161 | "source": [
162 | "x = np.array([0, 1, 2, 5, 0])\n",
163 | "y = np.array([0, 1, 4])\n"
164 | ]
165 | },
166 | {
167 | "cell_type": "markdown",
168 | "metadata": {},
169 | "source": [
170 | "Q5. Find the xor elements of x and y."
171 | ]
172 | },
173 | {
174 | "cell_type": "code",
175 | "execution_count": 40,
176 | "metadata": {},
177 | "outputs": [
178 | {
179 | "name": "stdout",
180 | "output_type": "stream",
181 | "text": [
182 | "[2 4 5]\n"
183 | ]
184 | }
185 | ],
186 | "source": [
187 | "x = np.array([0, 1, 2, 5, 0])\n",
188 | "y = np.array([0, 1, 4])\n",
189 | "out1 = np.setxor1d(x, y)\n",
190 | "out2 = np.sort(np.concatenate((np.setdiff1d(x, y), np.setdiff1d(y, x))))\n",
191 | "assert np.allclose(out1, out2)\n",
192 | "\n"
193 | ]
194 | },
195 | {
196 | "cell_type": "markdown",
197 | "metadata": {},
198 | "source": [
199 | "Q6. Find the union of x and y."
200 | ]
201 | },
202 | {
203 | "cell_type": "code",
204 | "execution_count": 42,
205 | "metadata": {},
206 | "outputs": [
207 | {
208 | "name": "stdout",
209 | "output_type": "stream",
210 | "text": [
211 | "[0 1 2 4 5]\n"
212 | ]
213 | }
214 | ],
215 | "source": [
216 | "x = np.array([0, 1, 2, 5, 0])\n",
217 | "y = np.array([0, 1, 4])\n",
218 | "out1 = np.union1d(x, y)\n",
219 | "out2 = np.sort(np.unique(np.concatenate((x, y))))\n",
220 | "assert np.allclose(out1, out2)\n"
221 | ]
222 | },
223 | {
224 | "cell_type": "code",
225 | "execution_count": null,
226 | "metadata": {
227 | "collapsed": true
228 | },
229 | "outputs": [],
230 | "source": []
231 | }
232 | ],
233 | "metadata": {
234 | "kernelspec": {
235 | "display_name": "Python 3",
236 | "language": "python",
237 | "name": "python3"
238 | },
239 | "language_info": {
240 | "codemirror_mode": {
241 | "name": "ipython",
242 | "version": 3
243 | },
244 | "file_extension": ".py",
245 | "mimetype": "text/x-python",
246 | "name": "python",
247 | "nbconvert_exporter": "python",
248 | "pygments_lexer": "ipython3",
249 | "version": "3.6.2"
250 | }
251 | },
252 | "nbformat": 4,
253 | "nbformat_minor": 1
254 | }
255 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/03-numpy-help-functions.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 2,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import numpy as np"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": 3,
15 | "metadata": {},
16 | "outputs": [
17 | {
18 | "data": {
19 | "text/plain": [
20 | "'1.13.3'"
21 | ]
22 | },
23 | "execution_count": 3,
24 | "metadata": {},
25 | "output_type": "execute_result"
26 | }
27 | ],
28 | "source": [
29 | "np.__version__"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "Q1. Search for docstrings of the numpy functions on linear algebra."
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": 5,
42 | "metadata": {},
43 | "outputs": [
44 | {
45 | "name": "stdout",
46 | "output_type": "stream",
47 | "text": [
48 | "Search results for 'linear algebra'\n",
49 | "-----------------------------------\n",
50 | "numpy.linalg.solve\n",
51 | " Solve a linear matrix equation, or system of linear scalar equations.\n",
52 | "numpy.poly\n",
53 | " Find the coefficients of a polynomial with the given sequence of roots.\n",
54 | "numpy.linalg.eig\n",
55 | " Compute the eigenvalues and right eigenvectors of a square array.\n",
56 | "numpy.linalg.cond\n",
57 | " Compute the condition number of a matrix.\n",
58 | "numpy.linalg.eigh\n",
59 | " Return the eigenvalues and eigenvectors of a Hermitian or symmetric matrix.\n",
60 | "numpy.linalg.pinv\n",
61 | " Compute the (Moore-Penrose) pseudo-inverse of a matrix.\n",
62 | "numpy.linalg.LinAlgError\n",
63 | " Generic Python-exception-derived object raised by linalg functions.\n"
64 | ]
65 | }
66 | ],
67 | "source": [
68 | "np.lookfor(\"linear algebra\")"
69 | ]
70 | },
71 | {
72 | "cell_type": "markdown",
73 | "metadata": {},
74 | "source": [
75 | "Q2. Get help information for numpy dot function."
76 | ]
77 | },
78 | {
79 | "cell_type": "code",
80 | "execution_count": 9,
81 | "metadata": {},
82 | "outputs": [
83 | {
84 | "name": "stdout",
85 | "output_type": "stream",
86 | "text": [
87 | "dot(a, b, out=None)\n",
88 | "\n",
89 | "Dot product of two arrays.\n",
90 | "\n",
91 | "For 2-D arrays it is equivalent to matrix multiplication, and for 1-D\n",
92 | "arrays to inner product of vectors (without complex conjugation). For\n",
93 | "N dimensions it is a sum product over the last axis of `a` and\n",
94 | "the second-to-last of `b`::\n",
95 | "\n",
96 | " dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])\n",
97 | "\n",
98 | "Parameters\n",
99 | "----------\n",
100 | "a : array_like\n",
101 | " First argument.\n",
102 | "b : array_like\n",
103 | " Second argument.\n",
104 | "out : ndarray, optional\n",
105 | " Output argument. This must have the exact kind that would be returned\n",
106 | " if it was not used. In particular, it must have the right type, must be\n",
107 | " C-contiguous, and its dtype must be the dtype that would be returned\n",
108 | " for `dot(a,b)`. This is a performance feature. Therefore, if these\n",
109 | " conditions are not met, an exception is raised, instead of attempting\n",
110 | " to be flexible.\n",
111 | "\n",
112 | "Returns\n",
113 | "-------\n",
114 | "output : ndarray\n",
115 | " Returns the dot product of `a` and `b`. If `a` and `b` are both\n",
116 | " scalars or both 1-D arrays then a scalar is returned; otherwise\n",
117 | " an array is returned.\n",
118 | " If `out` is given, then it is returned.\n",
119 | "\n",
120 | "Raises\n",
121 | "------\n",
122 | "ValueError\n",
123 | " If the last dimension of `a` is not the same size as\n",
124 | " the second-to-last dimension of `b`.\n",
125 | "\n",
126 | "See Also\n",
127 | "--------\n",
128 | "vdot : Complex-conjugating dot product.\n",
129 | "tensordot : Sum products over arbitrary axes.\n",
130 | "einsum : Einstein summation convention.\n",
131 | "matmul : '@' operator as method with out parameter.\n",
132 | "\n",
133 | "Examples\n",
134 | "--------\n",
135 | ">>> np.dot(3, 4)\n",
136 | "12\n",
137 | "\n",
138 | "Neither argument is complex-conjugated:\n",
139 | "\n",
140 | ">>> np.dot([2j, 3j], [2j, 3j])\n",
141 | "(-13+0j)\n",
142 | "\n",
143 | "For 2-D arrays it is the matrix product:\n",
144 | "\n",
145 | ">>> a = [[1, 0], [0, 1]]\n",
146 | ">>> b = [[4, 1], [2, 2]]\n",
147 | ">>> np.dot(a, b)\n",
148 | "array([[4, 1],\n",
149 | " [2, 2]])\n",
150 | "\n",
151 | ">>> a = np.arange(3*4*5*6).reshape((3,4,5,6))\n",
152 | ">>> b = np.arange(3*4*5*6)[::-1].reshape((5,4,6,3))\n",
153 | ">>> np.dot(a, b)[2,3,2,1,2,2]\n",
154 | "499128\n",
155 | ">>> sum(a[2,3,2,:] * b[1,2,:,2])\n",
156 | "499128\n"
157 | ]
158 | }
159 | ],
160 | "source": []
161 | },
162 | {
163 | "cell_type": "code",
164 | "execution_count": null,
165 | "metadata": {
166 | "collapsed": true
167 | },
168 | "outputs": [],
169 | "source": []
170 | }
171 | ],
172 | "metadata": {
173 | "kernelspec": {
174 | "display_name": "Python 3",
175 | "language": "python",
176 | "name": "python3"
177 | },
178 | "language_info": {
179 | "codemirror_mode": {
180 | "name": "ipython",
181 | "version": 3
182 | },
183 | "file_extension": ".py",
184 | "mimetype": "text/x-python",
185 | "name": "python",
186 | "nbconvert_exporter": "python",
187 | "pygments_lexer": "ipython3",
188 | "version": "3.6.2"
189 | }
190 | },
191 | "nbformat": 4,
192 | "nbformat_minor": 1
193 | }
194 |
--------------------------------------------------------------------------------
/0-libraries/pytorch-exercises/Chapter1_Tensors/2-random-sampling.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Random Sampling"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 1,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": [
16 | "from __future__ import print_function\n",
17 | "import torch\n",
18 | "import numpy as np"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 2,
24 | "metadata": {},
25 | "outputs": [
26 | {
27 | "data": {
28 | "text/plain": [
29 | "datetime.date(2017, 9, 26)"
30 | ]
31 | },
32 | "execution_count": 2,
33 | "metadata": {},
34 | "output_type": "execute_result"
35 | }
36 | ],
37 | "source": [
38 | "from datetime import date\n",
39 | "date.today()"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": 3,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "author = \"kyubyong. https://github.com/Kyubyong/pytorch_exercises\""
49 | ]
50 | },
51 | {
52 | "cell_type": "code",
53 | "execution_count": 4,
54 | "metadata": {},
55 | "outputs": [
56 | {
57 | "data": {
58 | "text/plain": [
59 | "'0.2.0_3'"
60 | ]
61 | },
62 | "execution_count": 4,
63 | "metadata": {},
64 | "output_type": "execute_result"
65 | }
66 | ],
67 | "source": [
68 | "torch.__version__"
69 | ]
70 | },
71 | {
72 | "cell_type": "code",
73 | "execution_count": 5,
74 | "metadata": {},
75 | "outputs": [
76 | {
77 | "data": {
78 | "text/plain": [
79 | "'1.13.0'"
80 | ]
81 | },
82 | "execution_count": 5,
83 | "metadata": {},
84 | "output_type": "execute_result"
85 | }
86 | ],
87 | "source": [
88 | "np.__version__"
89 | ]
90 | },
91 | {
92 | "cell_type": "markdown",
93 | "metadata": {},
94 | "source": [
95 | "NOTE on notation\n",
96 | "\n",
97 | "_x, _y, _z, ...: NumPy 0-d or 1-d arrays
\n",
98 | "_X, _Y, _Z, ...: NumPy 2-d or higer dimensional arrays
\n",
99 | "x, y, z, ...: 0-d or 1-d tensors
\n",
100 | "X, Y, Z, ...: 2-d or higher dimensional tensors"
101 | ]
102 | },
103 | {
104 | "cell_type": "markdown",
105 | "metadata": {},
106 | "source": [
107 | "## Simple random data"
108 | ]
109 | },
110 | {
111 | "cell_type": "markdown",
112 | "metadata": {},
113 | "source": [
114 | "Q1. Create a tensor of shape (3, 2) and populate it with random samples from a **uniform distribution** over [0, 1)."
115 | ]
116 | },
117 | {
118 | "cell_type": "code",
119 | "execution_count": 8,
120 | "metadata": {},
121 | "outputs": [
122 | {
123 | "name": "stdout",
124 | "output_type": "stream",
125 | "text": [
126 | "\n",
127 | " 0.5950 0.7434\n",
128 | " 0.9752 0.8419\n",
129 | " 0.7158 0.3315\n",
130 | "[torch.FloatTensor of size 3x2]\n",
131 | "\n"
132 | ]
133 | }
134 | ],
135 | "source": [
136 | "X = ...\n",
137 | "print(X)\n"
138 | ]
139 | },
140 | {
141 | "cell_type": "markdown",
142 | "metadata": {},
143 | "source": [
144 | "Q2. Create a tensor of shape (3, 2) and populate it with random samples from a **normal distribution** with zero mean and variance of one."
145 | ]
146 | },
147 | {
148 | "cell_type": "code",
149 | "execution_count": 9,
150 | "metadata": {},
151 | "outputs": [
152 | {
153 | "name": "stdout",
154 | "output_type": "stream",
155 | "text": [
156 | "\n",
157 | " 1.1495 -0.0553\n",
158 | " 0.0182 0.1149\n",
159 | " 0.0390 -0.7320\n",
160 | "[torch.FloatTensor of size 3x2]\n",
161 | "\n"
162 | ]
163 | }
164 | ],
165 | "source": [
166 | "X = ...\n",
167 | "print(X)\n"
168 | ]
169 | },
170 | {
171 | "cell_type": "markdown",
172 | "metadata": {},
173 | "source": [
174 | "Q3. Create a tensor of random numbers drawn from the given mean and standard deviation."
175 | ]
176 | },
177 | {
178 | "cell_type": "code",
179 | "execution_count": 13,
180 | "metadata": {},
181 | "outputs": [
182 | {
183 | "name": "stdout",
184 | "output_type": "stream",
185 | "text": [
186 | "\n",
187 | " 1.1495 -0.0553\n",
188 | " 0.0182 0.1149\n",
189 | " 0.0390 -0.7320\n",
190 | "[torch.FloatTensor of size 3x2]\n",
191 | "\n"
192 | ]
193 | }
194 | ],
195 | "source": [
196 | "means = torch.Tensor([1, 2, 3])\n",
197 | "std = torch.Tensor([0.1, 0., -0.1])\n",
198 | "X = ...\n",
199 | "print(X)"
200 | ]
201 | },
202 | {
203 | "cell_type": "markdown",
204 | "metadata": {},
205 | "source": [
206 | "## Permutations"
207 | ]
208 | },
209 | {
210 | "cell_type": "markdown",
211 | "metadata": {},
212 | "source": [
213 | "Q4. Shuffle integers between 0 and 10 (exclusive)."
214 | ]
215 | },
216 | {
217 | "cell_type": "code",
218 | "execution_count": 12,
219 | "metadata": {},
220 | "outputs": [
221 | {
222 | "name": "stdout",
223 | "output_type": "stream",
224 | "text": [
225 | "\n",
226 | " 0\n",
227 | " 9\n",
228 | " 7\n",
229 | " 8\n",
230 | " 5\n",
231 | " 4\n",
232 | " 3\n",
233 | " 1\n",
234 | " 6\n",
235 | " 2\n",
236 | "[torch.LongTensor of size 10]\n",
237 | "\n"
238 | ]
239 | }
240 | ],
241 | "source": [
242 | "x = ...\n",
243 | "print(x)\n"
244 | ]
245 | }
246 | ],
247 | "metadata": {
248 | "kernelspec": {
249 | "display_name": "Python 2",
250 | "language": "python",
251 | "name": "python2"
252 | },
253 | "language_info": {
254 | "codemirror_mode": {
255 | "name": "ipython",
256 | "version": 2
257 | },
258 | "file_extension": ".py",
259 | "mimetype": "text/x-python",
260 | "name": "python",
261 | "nbconvert_exporter": "python",
262 | "pygments_lexer": "ipython2",
263 | "version": "2.7.10"
264 | }
265 | },
266 | "nbformat": 4,
267 | "nbformat_minor": 1
268 | }
269 |
--------------------------------------------------------------------------------
/0-libraries/pytorch-exercises/Chapter1_Tensors/2-random-sampling-solution.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Random Sampling"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 1,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": [
16 | "from __future__ import print_function\n",
17 | "import torch\n",
18 | "import numpy as np"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 2,
24 | "metadata": {},
25 | "outputs": [
26 | {
27 | "data": {
28 | "text/plain": [
29 | "datetime.date(2017, 9, 27)"
30 | ]
31 | },
32 | "execution_count": 2,
33 | "metadata": {},
34 | "output_type": "execute_result"
35 | }
36 | ],
37 | "source": [
38 | "from datetime import date\n",
39 | "date.today()"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": 3,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "author = \"kyubyong. https://github.com/Kyubyong/pytorch_exercises\""
49 | ]
50 | },
51 | {
52 | "cell_type": "code",
53 | "execution_count": 4,
54 | "metadata": {},
55 | "outputs": [
56 | {
57 | "data": {
58 | "text/plain": [
59 | "'0.2.0_3'"
60 | ]
61 | },
62 | "execution_count": 4,
63 | "metadata": {},
64 | "output_type": "execute_result"
65 | }
66 | ],
67 | "source": [
68 | "torch.__version__"
69 | ]
70 | },
71 | {
72 | "cell_type": "code",
73 | "execution_count": 5,
74 | "metadata": {},
75 | "outputs": [
76 | {
77 | "data": {
78 | "text/plain": [
79 | "'1.13.0'"
80 | ]
81 | },
82 | "execution_count": 5,
83 | "metadata": {},
84 | "output_type": "execute_result"
85 | }
86 | ],
87 | "source": [
88 | "np.__version__"
89 | ]
90 | },
91 | {
92 | "cell_type": "markdown",
93 | "metadata": {},
94 | "source": [
95 | "NOTE on notation\n",
96 | "\n",
97 | "_x, _y, _z, ...: NumPy 0-d or 1-d arrays
\n",
98 | "_X, _Y, _Z, ...: NumPy 2-d or higer dimensional arrays
\n",
99 | "x, y, z, ...: 0-d or 1-d tensors
\n",
100 | "X, Y, Z, ...: 2-d or higher dimensional tensors"
101 | ]
102 | },
103 | {
104 | "cell_type": "markdown",
105 | "metadata": {},
106 | "source": [
107 | "## Simple random data"
108 | ]
109 | },
110 | {
111 | "cell_type": "markdown",
112 | "metadata": {},
113 | "source": [
114 | "Q1. Create a tensor of shape (3, 2) and populate it with random samples from a **uniform distribution** over [0, 1)."
115 | ]
116 | },
117 | {
118 | "cell_type": "code",
119 | "execution_count": 6,
120 | "metadata": {},
121 | "outputs": [
122 | {
123 | "name": "stdout",
124 | "output_type": "stream",
125 | "text": [
126 | "\n",
127 | " 0.2166 0.4383\n",
128 | " 0.0214 0.9917\n",
129 | " 0.8378 0.5924\n",
130 | "[torch.FloatTensor of size 3x2]\n",
131 | "\n"
132 | ]
133 | }
134 | ],
135 | "source": [
136 | "X = torch.rand(3, 2)\n",
137 | "print(X)\n",
138 | "\n",
139 | "# cf\n",
140 | "# np.random.rand(3, 2) "
141 | ]
142 | },
143 | {
144 | "cell_type": "markdown",
145 | "metadata": {},
146 | "source": [
147 | "Q2. Create a tensor of shape (3, 2) and populate it with random samples from a **normal distribution** with zero mean and variance of one."
148 | ]
149 | },
150 | {
151 | "cell_type": "code",
152 | "execution_count": 7,
153 | "metadata": {},
154 | "outputs": [
155 | {
156 | "name": "stdout",
157 | "output_type": "stream",
158 | "text": [
159 | "\n",
160 | " 0.9536 0.3673\n",
161 | "-1.1265 2.2443\n",
162 | " 0.7806 0.0989\n",
163 | "[torch.FloatTensor of size 3x2]\n",
164 | "\n"
165 | ]
166 | }
167 | ],
168 | "source": [
169 | "X = torch.randn(3, 2)\n",
170 | "print(X)\n",
171 | "\n",
172 | "# cf.\n",
173 | "# np.random.randn(3, 2)"
174 | ]
175 | },
176 | {
177 | "cell_type": "markdown",
178 | "metadata": {},
179 | "source": [
180 | "Q3. Create a tensor of random numbers drawn from the given mean and standard deviation."
181 | ]
182 | },
183 | {
184 | "cell_type": "code",
185 | "execution_count": 8,
186 | "metadata": {},
187 | "outputs": [
188 | {
189 | "name": "stdout",
190 | "output_type": "stream",
191 | "text": [
192 | "\n",
193 | " 1.0411\n",
194 | " 2.0000\n",
195 | " 3.0156\n",
196 | "[torch.FloatTensor of size 3]\n",
197 | "\n"
198 | ]
199 | }
200 | ],
201 | "source": [
202 | "means = torch.Tensor([1, 2, 3])\n",
203 | "std = torch.Tensor([0.1, 0., -0.1])\n",
204 | "X = torch.normal(means=means, std=std)\n",
205 | "print(X)"
206 | ]
207 | },
208 | {
209 | "cell_type": "markdown",
210 | "metadata": {},
211 | "source": [
212 | "## Permutations"
213 | ]
214 | },
215 | {
216 | "cell_type": "markdown",
217 | "metadata": {},
218 | "source": [
219 | "Q4. Shuffle integers between 0 and 10 (exclusive)."
220 | ]
221 | },
222 | {
223 | "cell_type": "code",
224 | "execution_count": 9,
225 | "metadata": {},
226 | "outputs": [
227 | {
228 | "name": "stdout",
229 | "output_type": "stream",
230 | "text": [
231 | "\n",
232 | " 4\n",
233 | " 9\n",
234 | " 1\n",
235 | " 3\n",
236 | " 7\n",
237 | " 0\n",
238 | " 8\n",
239 | " 5\n",
240 | " 6\n",
241 | " 2\n",
242 | "[torch.LongTensor of size 10]\n",
243 | "\n"
244 | ]
245 | }
246 | ],
247 | "source": [
248 | "x = torch.randperm(10)\n",
249 | "print(x)\n",
250 | "\n",
251 | "# cf.\n",
252 | "# np.random.permutation(10)"
253 | ]
254 | }
255 | ],
256 | "metadata": {
257 | "kernelspec": {
258 | "display_name": "Python 2",
259 | "language": "python",
260 | "name": "python2"
261 | },
262 | "language_info": {
263 | "codemirror_mode": {
264 | "name": "ipython",
265 | "version": 2
266 | },
267 | "file_extension": ".py",
268 | "mimetype": "text/x-python",
269 | "name": "python",
270 | "nbconvert_exporter": "python",
271 | "pygments_lexer": "ipython2",
272 | "version": "2.7.10"
273 | }
274 | },
275 | "nbformat": 4,
276 | "nbformat_minor": 1
277 | }
278 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Czech.txt:
--------------------------------------------------------------------------------
1 | Abl
2 | Adsit
3 | Ajdrna
4 | Alt
5 | Antonowitsch
6 | Antonowitz
7 | Bacon
8 | Ballalatak
9 | Ballaltick
10 | Bartonova
11 | Bastl
12 | Baroch
13 | Benesch
14 | Betlach
15 | Biganska
16 | Bilek
17 | Blahut
18 | Blazek
19 | Blazek
20 | Blazejovsky
21 | Blecha
22 | Bleskan
23 | Blober
24 | Bock
25 | Bohac
26 | Bohunovsky
27 | Bolcar
28 | Borovka
29 | Borovski
30 | Borowski
31 | Borovsky
32 | Brabbery
33 | Brezovjak
34 | Brousil
35 | Bruckner
36 | Buchta
37 | Cablikova
38 | Camfrlova
39 | Cap
40 | Cerda
41 | Cermak
42 | Chermak
43 | Cermak
44 | Cernochova
45 | Cernohous
46 | Cerny
47 | Cerney
48 | Cerny
49 | Cerv
50 | Cervenka
51 | Chalupka
52 | Charlott
53 | Chemlik
54 | Chicken
55 | Chilar
56 | Chromy
57 | Cihak
58 | Clineburg
59 | Klineberg
60 | Cober
61 | Colling
62 | Cvacek
63 | Czabal
64 | Damell
65 | Demall
66 | Dehmel
67 | Dana
68 | Dejmal
69 | Dempko
70 | Demko
71 | Dinko
72 | Divoky
73 | Dolejsi
74 | Dolezal
75 | Doljs
76 | Dopita
77 | Drassal
78 | Driml
79 | Duyava
80 | Dvorak
81 | Dziadik
82 | Egr
83 | Entler
84 | Faltysek
85 | Faltejsek
86 | Fencl
87 | Fenyo
88 | Fillipova
89 | Finfera
90 | Finferovy
91 | Finke
92 | Fojtikova
93 | Fremut
94 | Friedrich
95 | Frierdich
96 | Fritsch
97 | Furtsch
98 | Gabrisova
99 | Gavalok
100 | Geier
101 | Georgijev
102 | Geryk
103 | Giersig
104 | Glatter
105 | Glockl
106 | Grabski
107 | Grozmanova
108 | Grulich
109 | Grygarova
110 | Hadash
111 | Hafernik
112 | Hajek
113 | Hajicek
114 | Hajkova
115 | Hana
116 | Hanek
117 | Hanek
118 | Hanika
119 | Hanusch
120 | Hanzlick
121 | Handzlik
122 | Hanzlik
123 | Harger
124 | Hartl
125 | Havlatova
126 | Havlice
127 | Hawlata
128 | Heidl
129 | Herback
130 | Herodes
131 | Hiorvst
132 | Hladky
133 | Hlavsa
134 | Hnizdil
135 | Hodowal
136 | Hodoval
137 | Holan
138 | Holub
139 | Homulka
140 | Hora
141 | Hovanec
142 | Hrabak
143 | Hradek
144 | Hrdy
145 | Hrula
146 | Hruska
147 | Hruskova
148 | Hudecek
149 | Husk
150 | Hynna
151 | Jaluvka
152 | Janca
153 | Janicek
154 | Jenicek
155 | Janacek
156 | Janick
157 | Janoch
158 | Janosik
159 | Janutka
160 | Jares
161 | Jarzembowski
162 | Jedlicka
163 | Jelinek
164 | Jindra
165 | Jirava
166 | Jirik
167 | Jirku
168 | Jirovy
169 | Jobst
170 | Jonas
171 | Kacirek
172 | Kafka
173 | Kafka
174 | Kaiser
175 | Kanak
176 | Kaplanek
177 | Kara
178 | Karlovsky
179 | Kasa
180 | Kasimor
181 | Kazimor
182 | Kazmier
183 | Katschker
184 | Kauphsman
185 | Kenzel
186 | Kerner
187 | Kesl
188 | Kessel
189 | Kessler
190 | Khork
191 | Kirchma
192 | Klein
193 | Klemper
194 | Klimes
195 | Kober
196 | Koberna
197 | Koci
198 | Kocian
199 | Kocian
200 | Kofron
201 | Kolacny
202 | Koliha
203 | Kolman
204 | Koma
205 | Komo
206 | Coma
207 | Konarik
208 | Kopp
209 | Kopecky
210 | Korandak
211 | Korycan
212 | Korycansky
213 | Kosko
214 | Kouba
215 | Kouba
216 | Koukal
217 | Koza
218 | Kozumplikova
219 | Kratschmar
220 | Krawiec
221 | Kreisinger
222 | Kremlacek
223 | Kremlicka
224 | Kreutschmer
225 | Krhovsky
226 | Krivan
227 | Krivolavy
228 | Kriz
229 | Kruessel
230 | Krupala
231 | Krytinar
232 | Kubin
233 | Kucera
234 | Kucharova
235 | Kudrna
236 | Kuffel
237 | Kupfel
238 | Kofel
239 | Kulhanek
240 | Kunik
241 | Kurtz
242 | Kusak
243 | Kvasnicka
244 | Lawa
245 | Linart
246 | Lind
247 | Lokay
248 | Loskot
249 | Ludwig
250 | Lynsmeier
251 | Macha
252 | Machacek
253 | Macikova
254 | Malafa
255 | Malec
256 | Malecha
257 | Maly
258 | Marek
259 | Marik
260 | Marik
261 | Markytan
262 | Matejka
263 | Matjeka
264 | Matocha
265 | Maxa/B
266 | Mayer
267 | Meier
268 | Merta
269 | Meszes
270 | Metjeka
271 | Michalovic
272 | Michalovicova
273 | Miksatkova
274 | Mojzis
275 | Mojjis
276 | Mozzis
277 | Molcan
278 | Monfort
279 | MonkoAustria
280 | Morava
281 | Morek
282 | Muchalon
283 | Mudra
284 | Muhlbauer
285 | Nadvornizch
286 | Nadwornik
287 | Navara
288 | Navratil
289 | Navratil
290 | Navrkal
291 | Nekuza
292 | Nemec
293 | Nemecek
294 | Nestrojil
295 | Netsch
296 | Neusser
297 | Neisser
298 | Naizer
299 | Novak
300 | Nowak
301 | Novotny
302 | Novy Novy
303 | Oborny
304 | Ocasek
305 | Ocaskova
306 | Oesterreicher
307 | Okenfuss
308 | Olbrich
309 | Ondrisek
310 | Opizka
311 | Opova
312 | Opp
313 | Osladil
314 | Ozimuk
315 | Pachr
316 | Palzewicz
317 | Panek
318 | Patril
319 | Pavlik
320 | Pavlicka
321 | Pavlu
322 | Pawlak
323 | Pear
324 | Peary
325 | Pech
326 | Peisar
327 | Paisar
328 | Paiser
329 | Perevuznik
330 | Perina
331 | Persein
332 | Petrezelka
333 | Petru
334 | Pesek
335 | Petersen
336 | Pfeifer
337 | Picha
338 | Pillar
339 | Pellar
340 | Piller
341 | Pinter
342 | Pitterman
343 | Planick
344 | Piskach
345 | Plisek
346 | Plisko
347 | Pokorny
348 | Ponec
349 | Ponec
350 | Prachar
351 | Praseta
352 | Prchal
353 | Prehatney
354 | Pretsch
355 | Prill
356 | Psik
357 | Pudel
358 | Purdes
359 | Quasninsky
360 | Raffel
361 | Rafaj1
362 | Ransom
363 | Rezac
364 | Riedel
365 | Riha
366 | Riha
367 | Ritchie
368 | Rozinek
369 | Ruba
370 | Ruda
371 | Rumisek
372 | Ruzicka
373 | Rypka
374 | Rebka
375 | Rzehak
376 | Sabol
377 | Safko
378 | Samz
379 | Sankovsky
380 | Sappe
381 | Sappe
382 | Sarna
383 | Satorie
384 | Savchak
385 | Svotak
386 | Swatchak
387 | Svocak
388 | Svotchak
389 | Schallom
390 | Schenk
391 | Schlantz
392 | Schmeiser
393 | Schneider
394 | Schmied
395 | Schubert
396 | Schwarz
397 | Schwartz
398 | Sedmik
399 | Sedmikova
400 | Seger
401 | Sekovora
402 | Semick
403 | Serak
404 | Sherak
405 | Shima
406 | Shula
407 | Siegl
408 | Silhan
409 | Simecek
410 | Simodines
411 | Simonek
412 | Sip
413 | Sitta
414 | Skala
415 | Skeril
416 | Skokan
417 | Skomicka
418 | Skwor
419 | Slapnickova
420 | Slejtr
421 | Slepicka
422 | Slepica
423 | Slezak
424 | Slivka
425 | Smith
426 | Snelker
427 | Sokolik
428 | Soucek
429 | Soukup
430 | Soukup
431 | Spicka
432 | Spoerl
433 | Sponer
434 | Srda
435 | Srpcikova
436 | Stangl
437 | Stanzel
438 | Stary
439 | Staska
440 | Stedronsky
441 | Stegon
442 | Sztegon
443 | Steinborn
444 | Stepan
445 | Stites
446 | Stluka
447 | Stotzky
448 | StrakaO
449 | Stramba
450 | Stupka
451 | Subertova
452 | Suchanka
453 | Sula
454 | Svejda
455 | Svejkovsky
456 | Svoboda
457 | Tejc
458 | Tikal
459 | Tykal
460 | Till
461 | Timpe
462 | Timpy
463 | Toman
464 | Tomanek
465 | Tomasek
466 | Tomes
467 | Trampotova
468 | Trampota
469 | Treblik
470 | Trnkova
471 | Uerling
472 | Uhlik
473 | Urbanek
474 | Urbanek1
475 | Urbanovska
476 | Urista
477 | Ustohal
478 | Vaca
479 | Vaculova
480 | Vavra
481 | Vejvoda
482 | Veverka
483 | Victor
484 | Vlach
485 | Vlach
486 | Vlasak
487 | Vlasek
488 | Volcik
489 | Voneve
490 | Votke
491 | Vozab
492 | Vrazel
493 | Vykruta
494 | Wykruta
495 | Waclauska
496 | Weichert
497 | Weineltk
498 | Weisener
499 | Wiesner
500 | Wizner
501 | Weiss
502 | Werlla
503 | Whitmire1
504 | Widerlechner
505 | Wilchek
506 | Wondracek
507 | Wood
508 | Zajicek
509 | Zak
510 | Zajicek
511 | Zaruba
512 | Zaruba
513 | Zelinka
514 | Zeman
515 | Zimola
516 | Zipperer
517 | Zitka
518 | Zoucha
519 | Zwolenksy
520 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/09-random-sampling.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Random Sampling"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 2,
13 | "metadata": {
14 | "collapsed": true
15 | },
16 | "outputs": [],
17 | "source": [
18 | "import numpy as np"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 3,
24 | "metadata": {},
25 | "outputs": [
26 | {
27 | "data": {
28 | "text/plain": [
29 | "'1.11.2'"
30 | ]
31 | },
32 | "execution_count": 3,
33 | "metadata": {},
34 | "output_type": "execute_result"
35 | }
36 | ],
37 | "source": [
38 | "np.__version__"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": 5,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "__author__ = 'kyubyong. longinglove@nate.com'"
48 | ]
49 | },
50 | {
51 | "cell_type": "markdown",
52 | "metadata": {},
53 | "source": [
54 | "## Simple random data"
55 | ]
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "metadata": {},
60 | "source": [
61 | "Q1. Create an array of shape (3, 2) and populate it with random samples from a uniform distribution over [0, 1)."
62 | ]
63 | },
64 | {
65 | "cell_type": "code",
66 | "execution_count": 49,
67 | "metadata": {},
68 | "outputs": [
69 | {
70 | "data": {
71 | "text/plain": [
72 | "array([[ 0.13879034, 0.71300174],\n",
73 | " [ 0.08121322, 0.00393554],\n",
74 | " [ 0.02349471, 0.56677474]])"
75 | ]
76 | },
77 | "execution_count": 49,
78 | "metadata": {},
79 | "output_type": "execute_result"
80 | }
81 | ],
82 | "source": []
83 | },
84 | {
85 | "cell_type": "markdown",
86 | "metadata": {},
87 | "source": [
88 | "Q2. Create an array of shape (1000, 1000) and populate it with random samples from a standard normal distribution. And verify that the mean and standard deviation is close enough to 0 and 1 repectively."
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": 42,
94 | "metadata": {},
95 | "outputs": [
96 | {
97 | "name": "stdout",
98 | "output_type": "stream",
99 | "text": [
100 | "-0.00110028519551\n",
101 | "0.999683483393\n"
102 | ]
103 | }
104 | ],
105 | "source": []
106 | },
107 | {
108 | "cell_type": "markdown",
109 | "metadata": {},
110 | "source": [
111 | "Q3. Create an array of shape (3, 2) and populate it with random integers ranging from 0 to 3 (inclusive) from a discrete uniform distribution."
112 | ]
113 | },
114 | {
115 | "cell_type": "code",
116 | "execution_count": 44,
117 | "metadata": {},
118 | "outputs": [
119 | {
120 | "data": {
121 | "text/plain": [
122 | "array([[1, 3],\n",
123 | " [3, 0],\n",
124 | " [0, 0]])"
125 | ]
126 | },
127 | "execution_count": 44,
128 | "metadata": {},
129 | "output_type": "execute_result"
130 | }
131 | ],
132 | "source": []
133 | },
134 | {
135 | "cell_type": "markdown",
136 | "metadata": {},
137 | "source": [
138 | "Q4. Extract 1 elements from x randomly such that each of them would be associated with probabilities .3, .5, .2. Then print the result 10 times."
139 | ]
140 | },
141 | {
142 | "cell_type": "code",
143 | "execution_count": 3,
144 | "metadata": {},
145 | "outputs": [
146 | {
147 | "name": "stdout",
148 | "output_type": "stream",
149 | "text": [
150 | "5 out of 10\n",
151 | "2 out of 10\n",
152 | "3 out of 10\n",
153 | "5 out of 10\n",
154 | "2 out of 10\n",
155 | "5 out of 10\n",
156 | "2 out of 10\n",
157 | "2 out of 10\n",
158 | "2 out of 10\n",
159 | "5 out of 10\n"
160 | ]
161 | }
162 | ],
163 | "source": [
164 | "x = [b'3 out of 10', b'5 out of 10', b'2 out of 10']\n"
165 | ]
166 | },
167 | {
168 | "cell_type": "markdown",
169 | "metadata": {},
170 | "source": [
171 | "Q5. Extract 3 different integers from 0 to 9 randomly with the same probabilities."
172 | ]
173 | },
174 | {
175 | "cell_type": "code",
176 | "execution_count": 66,
177 | "metadata": {},
178 | "outputs": [
179 | {
180 | "data": {
181 | "text/plain": [
182 | "array([5, 4, 0])"
183 | ]
184 | },
185 | "execution_count": 66,
186 | "metadata": {},
187 | "output_type": "execute_result"
188 | }
189 | ],
190 | "source": []
191 | },
192 | {
193 | "cell_type": "markdown",
194 | "metadata": {},
195 | "source": [
196 | "## Permutations"
197 | ]
198 | },
199 | {
200 | "cell_type": "markdown",
201 | "metadata": {},
202 | "source": [
203 | "Q6. Shuffle numbers between 0 and 9 (inclusive)."
204 | ]
205 | },
206 | {
207 | "cell_type": "code",
208 | "execution_count": 86,
209 | "metadata": {},
210 | "outputs": [
211 | {
212 | "name": "stdout",
213 | "output_type": "stream",
214 | "text": [
215 | "[2 3 8 4 5 1 0 6 9 7]\n"
216 | ]
217 | }
218 | ],
219 | "source": []
220 | },
221 | {
222 | "cell_type": "code",
223 | "execution_count": 88,
224 | "metadata": {},
225 | "outputs": [
226 | {
227 | "name": "stdout",
228 | "output_type": "stream",
229 | "text": [
230 | "[5 2 7 4 1 0 6 8 9 3]\n"
231 | ]
232 | }
233 | ],
234 | "source": [
235 | "# Or\n"
236 | ]
237 | },
238 | {
239 | "cell_type": "markdown",
240 | "metadata": {},
241 | "source": [
242 | "## Random generator"
243 | ]
244 | },
245 | {
246 | "cell_type": "markdown",
247 | "metadata": {},
248 | "source": [
249 | "Q7. Assign number 10 to the seed of the random generator so that you can get the same value next time."
250 | ]
251 | },
252 | {
253 | "cell_type": "code",
254 | "execution_count": 91,
255 | "metadata": {
256 | "collapsed": true
257 | },
258 | "outputs": [],
259 | "source": []
260 | }
261 | ],
262 | "metadata": {
263 | "kernelspec": {
264 | "display_name": "Python 3",
265 | "language": "python",
266 | "name": "python3"
267 | },
268 | "language_info": {
269 | "codemirror_mode": {
270 | "name": "ipython",
271 | "version": 3
272 | },
273 | "file_extension": ".py",
274 | "mimetype": "text/x-python",
275 | "name": "python",
276 | "nbconvert_exporter": "python",
277 | "pygments_lexer": "ipython3",
278 | "version": "3.6.2"
279 | }
280 | },
281 | "nbformat": 4,
282 | "nbformat_minor": 1
283 | }
284 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/Set_routines_Solutions.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Set routines"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 4,
13 | "metadata": {
14 | "collapsed": true
15 | },
16 | "outputs": [],
17 | "source": [
18 | "import numpy as np"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 5,
24 | "metadata": {
25 | "collapsed": false
26 | },
27 | "outputs": [
28 | {
29 | "data": {
30 | "text/plain": [
31 | "'1.11.2'"
32 | ]
33 | },
34 | "execution_count": 5,
35 | "metadata": {},
36 | "output_type": "execute_result"
37 | }
38 | ],
39 | "source": [
40 | "np.__version__"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": 6,
46 | "metadata": {
47 | "collapsed": false
48 | },
49 | "outputs": [],
50 | "source": [
51 | "author = 'kyubyong. longinglove@nate.com'"
52 | ]
53 | },
54 | {
55 | "cell_type": "markdown",
56 | "metadata": {},
57 | "source": [
58 | "## Making proper sets"
59 | ]
60 | },
61 | {
62 | "cell_type": "markdown",
63 | "metadata": {},
64 | "source": [
65 | "Q1. Get unique elements and reconstruction indices from x. And reconstruct x."
66 | ]
67 | },
68 | {
69 | "cell_type": "code",
70 | "execution_count": 15,
71 | "metadata": {
72 | "collapsed": false
73 | },
74 | "outputs": [
75 | {
76 | "name": "stdout",
77 | "output_type": "stream",
78 | "text": [
79 | "unique elements = [1 2 3 4 6]\n",
80 | "reconstruction indices = [0 1 4 3 1 2 1]\n",
81 | "reconstructed = [1 2 6 4 2 3 2]\n"
82 | ]
83 | }
84 | ],
85 | "source": [
86 | "x = np.array([1, 2, 6, 4, 2, 3, 2])\n",
87 | "out, indices = np.unique(x, return_inverse=True)\n",
88 | "print \"unique elements =\", out\n",
89 | "print \"reconstruction indices =\", indices\n",
90 | "print \"reconstructed =\", out[indices]\n"
91 | ]
92 | },
93 | {
94 | "cell_type": "markdown",
95 | "metadata": {},
96 | "source": [
97 | "## Boolean operations"
98 | ]
99 | },
100 | {
101 | "cell_type": "markdown",
102 | "metadata": {},
103 | "source": [
104 | "Q2. Create a boolean array of the same shape as x. If each element of x is present in y, the result will be True, otherwise False."
105 | ]
106 | },
107 | {
108 | "cell_type": "code",
109 | "execution_count": 19,
110 | "metadata": {
111 | "collapsed": false
112 | },
113 | "outputs": [
114 | {
115 | "name": "stdout",
116 | "output_type": "stream",
117 | "text": [
118 | "[ True True False False True]\n"
119 | ]
120 | }
121 | ],
122 | "source": [
123 | "x = np.array([0, 1, 2, 5, 0])\n",
124 | "y = np.array([0, 1])\n",
125 | "print np.in1d(x, y)"
126 | ]
127 | },
128 | {
129 | "cell_type": "markdown",
130 | "metadata": {},
131 | "source": [
132 | "Q3. Find the unique intersection of x and y."
133 | ]
134 | },
135 | {
136 | "cell_type": "code",
137 | "execution_count": 20,
138 | "metadata": {
139 | "collapsed": false
140 | },
141 | "outputs": [
142 | {
143 | "name": "stdout",
144 | "output_type": "stream",
145 | "text": [
146 | "[0 1]\n"
147 | ]
148 | }
149 | ],
150 | "source": [
151 | "x = np.array([0, 1, 2, 5, 0])\n",
152 | "y = np.array([0, 1, 4])\n",
153 | "print np.intersect1d(x, y)"
154 | ]
155 | },
156 | {
157 | "cell_type": "markdown",
158 | "metadata": {},
159 | "source": [
160 | "Q4. Find the unique elements of x that are not present in y."
161 | ]
162 | },
163 | {
164 | "cell_type": "code",
165 | "execution_count": 21,
166 | "metadata": {
167 | "collapsed": false
168 | },
169 | "outputs": [
170 | {
171 | "name": "stdout",
172 | "output_type": "stream",
173 | "text": [
174 | "[2 5]\n"
175 | ]
176 | }
177 | ],
178 | "source": [
179 | "x = np.array([0, 1, 2, 5, 0])\n",
180 | "y = np.array([0, 1, 4])\n",
181 | "print np.setdiff1d(x, y)"
182 | ]
183 | },
184 | {
185 | "cell_type": "markdown",
186 | "metadata": {},
187 | "source": [
188 | "Q5. Find the xor elements of x and y."
189 | ]
190 | },
191 | {
192 | "cell_type": "code",
193 | "execution_count": 40,
194 | "metadata": {
195 | "collapsed": false
196 | },
197 | "outputs": [
198 | {
199 | "name": "stdout",
200 | "output_type": "stream",
201 | "text": [
202 | "[2 4 5]\n"
203 | ]
204 | }
205 | ],
206 | "source": [
207 | "x = np.array([0, 1, 2, 5, 0])\n",
208 | "y = np.array([0, 1, 4])\n",
209 | "out1 = np.setxor1d(x, y)\n",
210 | "out2 = np.sort(np.concatenate((np.setdiff1d(x, y), np.setdiff1d(y, x))))\n",
211 | "assert np.allclose(out1, out2)\n",
212 | "print out1\n"
213 | ]
214 | },
215 | {
216 | "cell_type": "markdown",
217 | "metadata": {},
218 | "source": [
219 | "Q6. Find the union of x and y."
220 | ]
221 | },
222 | {
223 | "cell_type": "code",
224 | "execution_count": 42,
225 | "metadata": {
226 | "collapsed": false
227 | },
228 | "outputs": [
229 | {
230 | "name": "stdout",
231 | "output_type": "stream",
232 | "text": [
233 | "[0 1 2 4 5]\n"
234 | ]
235 | }
236 | ],
237 | "source": [
238 | "x = np.array([0, 1, 2, 5, 0])\n",
239 | "y = np.array([0, 1, 4])\n",
240 | "out1 = np.union1d(x, y)\n",
241 | "out2 = np.sort(np.unique(np.concatenate((x, y))))\n",
242 | "assert np.allclose(out1, out2)\n",
243 | "print np.union1d(x, y)"
244 | ]
245 | },
246 | {
247 | "cell_type": "code",
248 | "execution_count": null,
249 | "metadata": {
250 | "collapsed": true
251 | },
252 | "outputs": [],
253 | "source": []
254 | }
255 | ],
256 | "metadata": {
257 | "kernelspec": {
258 | "display_name": "Python 2",
259 | "language": "python",
260 | "name": "python2"
261 | },
262 | "language_info": {
263 | "codemirror_mode": {
264 | "name": "ipython",
265 | "version": 2
266 | },
267 | "file_extension": ".py",
268 | "mimetype": "text/x-python",
269 | "name": "python",
270 | "nbconvert_exporter": "python",
271 | "pygments_lexer": "ipython2",
272 | "version": "2.7.10"
273 | }
274 | },
275 | "nbformat": 4,
276 | "nbformat_minor": 0
277 | }
278 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/07-logic-functions.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Logic functions"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 1,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": [
16 | "import numpy as np"
17 | ]
18 | },
19 | {
20 | "cell_type": "code",
21 | "execution_count": 2,
22 | "metadata": {},
23 | "outputs": [
24 | {
25 | "data": {
26 | "text/plain": [
27 | "'1.13.3'"
28 | ]
29 | },
30 | "execution_count": 2,
31 | "metadata": {},
32 | "output_type": "execute_result"
33 | }
34 | ],
35 | "source": [
36 | "np.__version__"
37 | ]
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "metadata": {},
42 | "source": [
43 | "## Truth value testing\n"
44 | ]
45 | },
46 | {
47 | "cell_type": "markdown",
48 | "metadata": {},
49 | "source": [
50 | "Q1. Let x be an arbitrary array. Return True if none of the elements of x is zero. Remind that 0 evaluates to False in python.\n"
51 | ]
52 | },
53 | {
54 | "cell_type": "code",
55 | "execution_count": 4,
56 | "metadata": {},
57 | "outputs": [
58 | {
59 | "name": "stdout",
60 | "output_type": "stream",
61 | "text": [
62 | "True\n",
63 | "False\n"
64 | ]
65 | }
66 | ],
67 | "source": [
68 | "x = np.array([1,2,3])\n",
69 | "#\n",
70 | "\n",
71 | "x = np.array([1,0,3])\n",
72 | "#"
73 | ]
74 | },
75 | {
76 | "cell_type": "markdown",
77 | "metadata": {},
78 | "source": [
79 | "Q2. Let x be an arbitrary array. Return True if any of the elements of x is non-zero."
80 | ]
81 | },
82 | {
83 | "cell_type": "code",
84 | "execution_count": 5,
85 | "metadata": {},
86 | "outputs": [
87 | {
88 | "name": "stdout",
89 | "output_type": "stream",
90 | "text": [
91 | "True\n",
92 | "False\n"
93 | ]
94 | }
95 | ],
96 | "source": [
97 | "x = np.array([1,0,0])\n",
98 | "#\n",
99 | "\n",
100 | "x = np.array([0,0,0])\n",
101 | "#"
102 | ]
103 | },
104 | {
105 | "cell_type": "markdown",
106 | "metadata": {},
107 | "source": [
108 | "## Array contents\n"
109 | ]
110 | },
111 | {
112 | "cell_type": "markdown",
113 | "metadata": {},
114 | "source": [
115 | "Q3. Predict the result of the following code."
116 | ]
117 | },
118 | {
119 | "cell_type": "code",
120 | "execution_count": 8,
121 | "metadata": {},
122 | "outputs": [],
123 | "source": [
124 | "x = np.array([1, 0, np.nan, np.inf])\n",
125 | "#print np.isfinite(x)"
126 | ]
127 | },
128 | {
129 | "cell_type": "markdown",
130 | "metadata": {},
131 | "source": [
132 | "Q4. Predict the result of the following code."
133 | ]
134 | },
135 | {
136 | "cell_type": "code",
137 | "execution_count": 10,
138 | "metadata": {},
139 | "outputs": [],
140 | "source": [
141 | "x = np.array([1, 0, np.nan, np.inf])\n",
142 | "#print np.isinf(x)"
143 | ]
144 | },
145 | {
146 | "cell_type": "markdown",
147 | "metadata": {},
148 | "source": [
149 | "Q5. Predict the result of the following code."
150 | ]
151 | },
152 | {
153 | "cell_type": "code",
154 | "execution_count": 12,
155 | "metadata": {
156 | "collapsed": true
157 | },
158 | "outputs": [],
159 | "source": [
160 | "x = np.array([1, 0, np.nan, np.inf])\n",
161 | "#print np.isnan(x)"
162 | ]
163 | },
164 | {
165 | "cell_type": "markdown",
166 | "metadata": {},
167 | "source": [
168 | "## Array type testing"
169 | ]
170 | },
171 | {
172 | "cell_type": "markdown",
173 | "metadata": {},
174 | "source": [
175 | "Q6. Predict the result of the following code."
176 | ]
177 | },
178 | {
179 | "cell_type": "code",
180 | "execution_count": 15,
181 | "metadata": {},
182 | "outputs": [],
183 | "source": [
184 | "x = np.array([1+1j, 1+0j, 4.5, 3, 2, 2j])\n",
185 | "#print np.iscomplex(x)"
186 | ]
187 | },
188 | {
189 | "cell_type": "markdown",
190 | "metadata": {},
191 | "source": [
192 | "Q7. Predict the result of the following code."
193 | ]
194 | },
195 | {
196 | "cell_type": "code",
197 | "execution_count": 18,
198 | "metadata": {},
199 | "outputs": [],
200 | "source": [
201 | "x = np.array([1+1j, 1+0j, 4.5, 3, 2, 2j])\n",
202 | "#print np.isreal(x)"
203 | ]
204 | },
205 | {
206 | "cell_type": "markdown",
207 | "metadata": {},
208 | "source": [
209 | "Q8. Predict the result of the following code."
210 | ]
211 | },
212 | {
213 | "cell_type": "code",
214 | "execution_count": 21,
215 | "metadata": {},
216 | "outputs": [],
217 | "source": [
218 | "#print np.isscalar(3)\n",
219 | "#print np.isscalar([3])\n",
220 | "#print np.isscalar(True)"
221 | ]
222 | },
223 | {
224 | "cell_type": "markdown",
225 | "metadata": {},
226 | "source": [
227 | "## Logical operations"
228 | ]
229 | },
230 | {
231 | "cell_type": "markdown",
232 | "metadata": {},
233 | "source": [
234 | "Q9. Predict the result of the following code."
235 | ]
236 | },
237 | {
238 | "cell_type": "code",
239 | "execution_count": 31,
240 | "metadata": {},
241 | "outputs": [],
242 | "source": [
243 | "#print np.logical_and([True, False], [False, False])\n",
244 | "#print np.logical_or([True, False, True], [True, False, False])\n",
245 | "#print np.logical_xor([True, False, True], [True, False, False])\n",
246 | "#print np.logical_not([True, False, 0, 1])\n"
247 | ]
248 | },
249 | {
250 | "cell_type": "markdown",
251 | "metadata": {},
252 | "source": [
253 | "## Comparison"
254 | ]
255 | },
256 | {
257 | "cell_type": "markdown",
258 | "metadata": {},
259 | "source": [
260 | "Q10. Predict the result of the following code."
261 | ]
262 | },
263 | {
264 | "cell_type": "code",
265 | "execution_count": 42,
266 | "metadata": {},
267 | "outputs": [],
268 | "source": [
269 | "#print np.allclose([3], [2.999999])\n",
270 | "#print np.array_equal([3], [2.999999])"
271 | ]
272 | },
273 | {
274 | "cell_type": "markdown",
275 | "metadata": {},
276 | "source": [
277 | "Q11. Write numpy comparison functions such that they return the results as you see."
278 | ]
279 | },
280 | {
281 | "cell_type": "code",
282 | "execution_count": 51,
283 | "metadata": {},
284 | "outputs": [
285 | {
286 | "name": "stdout",
287 | "output_type": "stream",
288 | "text": [
289 | "[ True False]\n",
290 | "[ True True]\n",
291 | "[False False]\n",
292 | "[False True]\n"
293 | ]
294 | }
295 | ],
296 | "source": [
297 | "x = np.array([4, 5])\n",
298 | "y = np.array([2, 5])\n",
299 | "#\n",
300 | "#\n",
301 | "#\n",
302 | "#"
303 | ]
304 | },
305 | {
306 | "cell_type": "markdown",
307 | "metadata": {},
308 | "source": [
309 | "Q12. Predict the result of the following code."
310 | ]
311 | },
312 | {
313 | "cell_type": "code",
314 | "execution_count": 50,
315 | "metadata": {},
316 | "outputs": [],
317 | "source": [
318 | "#print np.equal([1, 2], [1, 2.000001])\n",
319 | "#print np.isclose([1, 2], [1, 2.000001])"
320 | ]
321 | },
322 | {
323 | "cell_type": "code",
324 | "execution_count": null,
325 | "metadata": {
326 | "collapsed": true
327 | },
328 | "outputs": [],
329 | "source": []
330 | }
331 | ],
332 | "metadata": {
333 | "kernelspec": {
334 | "display_name": "Python 3",
335 | "language": "python",
336 | "name": "python3"
337 | },
338 | "language_info": {
339 | "codemirror_mode": {
340 | "name": "ipython",
341 | "version": 3
342 | },
343 | "file_extension": ".py",
344 | "mimetype": "text/x-python",
345 | "name": "python",
346 | "nbconvert_exporter": "python",
347 | "pygments_lexer": "ipython3",
348 | "version": "3.6.2"
349 | }
350 | },
351 | "nbformat": 4,
352 | "nbformat_minor": 2
353 | }
354 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/Logic_functions_Solutions.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Logic functions"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 1,
13 | "metadata": {
14 | "collapsed": true
15 | },
16 | "outputs": [],
17 | "source": [
18 | "import numpy as np"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 2,
24 | "metadata": {},
25 | "outputs": [
26 | {
27 | "data": {
28 | "text/plain": [
29 | "'1.11.2'"
30 | ]
31 | },
32 | "execution_count": 2,
33 | "metadata": {},
34 | "output_type": "execute_result"
35 | }
36 | ],
37 | "source": [
38 | "np.__version__"
39 | ]
40 | },
41 | {
42 | "cell_type": "markdown",
43 | "metadata": {},
44 | "source": [
45 | "## Truth value testing\n"
46 | ]
47 | },
48 | {
49 | "cell_type": "markdown",
50 | "metadata": {},
51 | "source": [
52 | "Q1. Let x be an arbitrary array. Return True if none of the elements of x is zero. Remind that 0 evaluates to False in python.\n"
53 | ]
54 | },
55 | {
56 | "cell_type": "code",
57 | "execution_count": 4,
58 | "metadata": {},
59 | "outputs": [
60 | {
61 | "name": "stdout",
62 | "output_type": "stream",
63 | "text": [
64 | "True\n",
65 | "False\n"
66 | ]
67 | }
68 | ],
69 | "source": [
70 | "x = np.array([1,2,3])\n",
71 | "print np.all(x)\n",
72 | "\n",
73 | "x = np.array([1,0,3])\n",
74 | "print np.all(x)"
75 | ]
76 | },
77 | {
78 | "cell_type": "markdown",
79 | "metadata": {},
80 | "source": [
81 | "Q2. Let x be an arbitrary array. Return True if any of the elements of x is non-zero."
82 | ]
83 | },
84 | {
85 | "cell_type": "code",
86 | "execution_count": 5,
87 | "metadata": {},
88 | "outputs": [
89 | {
90 | "name": "stdout",
91 | "output_type": "stream",
92 | "text": [
93 | "True\n",
94 | "False\n"
95 | ]
96 | }
97 | ],
98 | "source": [
99 | "x = np.array([1,0,0])\n",
100 | "print np.any(x)\n",
101 | "\n",
102 | "x = np.array([0,0,0])\n",
103 | "print np.any(x)"
104 | ]
105 | },
106 | {
107 | "cell_type": "markdown",
108 | "metadata": {},
109 | "source": [
110 | "## Array contents\n"
111 | ]
112 | },
113 | {
114 | "cell_type": "markdown",
115 | "metadata": {},
116 | "source": [
117 | "Q3. Predict the result of the following code."
118 | ]
119 | },
120 | {
121 | "cell_type": "code",
122 | "execution_count": 8,
123 | "metadata": {},
124 | "outputs": [],
125 | "source": [
126 | "x = np.array([1, 0, np.nan, np.inf])\n",
127 | "#print np.isfinite(x)"
128 | ]
129 | },
130 | {
131 | "cell_type": "markdown",
132 | "metadata": {},
133 | "source": [
134 | "Q4. Predict the result of the following code."
135 | ]
136 | },
137 | {
138 | "cell_type": "code",
139 | "execution_count": 10,
140 | "metadata": {},
141 | "outputs": [],
142 | "source": [
143 | "x = np.array([1, 0, np.nan, np.inf])\n",
144 | "#print np.isinf(x)"
145 | ]
146 | },
147 | {
148 | "cell_type": "markdown",
149 | "metadata": {},
150 | "source": [
151 | "Q5. Predict the result of the following code."
152 | ]
153 | },
154 | {
155 | "cell_type": "code",
156 | "execution_count": 12,
157 | "metadata": {
158 | "collapsed": true
159 | },
160 | "outputs": [],
161 | "source": [
162 | "x = np.array([1, 0, np.nan, np.inf])\n",
163 | "#print np.isnan(x)"
164 | ]
165 | },
166 | {
167 | "cell_type": "markdown",
168 | "metadata": {},
169 | "source": [
170 | "## Array type testing"
171 | ]
172 | },
173 | {
174 | "cell_type": "markdown",
175 | "metadata": {},
176 | "source": [
177 | "Q6. Predict the result of the following code."
178 | ]
179 | },
180 | {
181 | "cell_type": "code",
182 | "execution_count": 15,
183 | "metadata": {},
184 | "outputs": [],
185 | "source": [
186 | "x = np.array([1+1j, 1+0j, 4.5, 3, 2, 2j])\n",
187 | "#print np.iscomplex(x)"
188 | ]
189 | },
190 | {
191 | "cell_type": "markdown",
192 | "metadata": {},
193 | "source": [
194 | "Q7. Predict the result of the following code."
195 | ]
196 | },
197 | {
198 | "cell_type": "code",
199 | "execution_count": 18,
200 | "metadata": {},
201 | "outputs": [],
202 | "source": [
203 | "x = np.array([1+1j, 1+0j, 4.5, 3, 2, 2j])\n",
204 | "#print np.isreal(x)"
205 | ]
206 | },
207 | {
208 | "cell_type": "markdown",
209 | "metadata": {},
210 | "source": [
211 | "Q8. Predict the result of the following code."
212 | ]
213 | },
214 | {
215 | "cell_type": "code",
216 | "execution_count": 21,
217 | "metadata": {},
218 | "outputs": [],
219 | "source": [
220 | "#print np.isscalar(3)\n",
221 | "#print np.isscalar([3])\n",
222 | "#print np.isscalar(True)"
223 | ]
224 | },
225 | {
226 | "cell_type": "markdown",
227 | "metadata": {},
228 | "source": [
229 | "## Logical operations"
230 | ]
231 | },
232 | {
233 | "cell_type": "markdown",
234 | "metadata": {},
235 | "source": [
236 | "Q9. Predict the result of the following code."
237 | ]
238 | },
239 | {
240 | "cell_type": "code",
241 | "execution_count": 31,
242 | "metadata": {},
243 | "outputs": [],
244 | "source": [
245 | "#print np.logical_and([True, False], [False, False])\n",
246 | "#print np.logical_or([True, False, True], [True, False, False])\n",
247 | "#print np.logical_xor([True, False, True], [True, False, False])\n",
248 | "#print np.logical_not([True, False, 0, 1])\n"
249 | ]
250 | },
251 | {
252 | "cell_type": "markdown",
253 | "metadata": {},
254 | "source": [
255 | "## Comparison"
256 | ]
257 | },
258 | {
259 | "cell_type": "markdown",
260 | "metadata": {},
261 | "source": [
262 | "Q10. Predict the result of the following code."
263 | ]
264 | },
265 | {
266 | "cell_type": "code",
267 | "execution_count": 42,
268 | "metadata": {},
269 | "outputs": [],
270 | "source": [
271 | "#print np.allclose([3], [2.999999])\n",
272 | "#print np.array_equal([3], [2.999999])"
273 | ]
274 | },
275 | {
276 | "cell_type": "markdown",
277 | "metadata": {},
278 | "source": [
279 | "Q11. Write numpy comparison functions such that they return the results as you see."
280 | ]
281 | },
282 | {
283 | "cell_type": "code",
284 | "execution_count": 51,
285 | "metadata": {},
286 | "outputs": [
287 | {
288 | "name": "stdout",
289 | "output_type": "stream",
290 | "text": [
291 | "[ True False]\n",
292 | "[ True True]\n",
293 | "[False False]\n",
294 | "[False True]\n"
295 | ]
296 | }
297 | ],
298 | "source": [
299 | "x = np.array([4, 5])\n",
300 | "y = np.array([2, 5])\n",
301 | "print np.greater(x, y)\n",
302 | "print np.greater_equal(x, y)\n",
303 | "print np.less(x, y)\n",
304 | "print np.less_equal(x, y)\n"
305 | ]
306 | },
307 | {
308 | "cell_type": "markdown",
309 | "metadata": {},
310 | "source": [
311 | "Q12. Predict the result of the following code."
312 | ]
313 | },
314 | {
315 | "cell_type": "code",
316 | "execution_count": 50,
317 | "metadata": {},
318 | "outputs": [],
319 | "source": [
320 | "#print np.equal([1, 2], [1, 2.000001])\n",
321 | "#print np.isclose([1, 2], [1, 2.000001])"
322 | ]
323 | },
324 | {
325 | "cell_type": "code",
326 | "execution_count": null,
327 | "metadata": {
328 | "collapsed": true
329 | },
330 | "outputs": [],
331 | "source": []
332 | }
333 | ],
334 | "metadata": {
335 | "kernelspec": {
336 | "display_name": "Python 3",
337 | "language": "python",
338 | "name": "python3"
339 | },
340 | "language_info": {
341 | "codemirror_mode": {
342 | "name": "ipython",
343 | "version": 3
344 | },
345 | "file_extension": ".py",
346 | "mimetype": "text/x-python",
347 | "name": "python",
348 | "nbconvert_exporter": "python",
349 | "pygments_lexer": "ipython3",
350 | "version": "3.6.2"
351 | }
352 | },
353 | "nbformat": 4,
354 | "nbformat_minor": 2
355 | }
356 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/Random_sampling_Solutions.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Random Sampling"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 2,
13 | "metadata": {
14 | "collapsed": true
15 | },
16 | "outputs": [],
17 | "source": [
18 | "import numpy as np"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 3,
24 | "metadata": {
25 | "collapsed": false
26 | },
27 | "outputs": [
28 | {
29 | "data": {
30 | "text/plain": [
31 | "'1.11.2'"
32 | ]
33 | },
34 | "execution_count": 3,
35 | "metadata": {},
36 | "output_type": "execute_result"
37 | }
38 | ],
39 | "source": [
40 | "np.__version__"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": 5,
46 | "metadata": {
47 | "collapsed": false
48 | },
49 | "outputs": [],
50 | "source": [
51 | "__author__ = 'kyubyong. longinglove@nate.com'"
52 | ]
53 | },
54 | {
55 | "cell_type": "markdown",
56 | "metadata": {},
57 | "source": [
58 | "## Simple random data"
59 | ]
60 | },
61 | {
62 | "cell_type": "markdown",
63 | "metadata": {},
64 | "source": [
65 | "Q1. Create an array of shape (3, 2) and populate it with random samples from a uniform distribution over [0, 1)."
66 | ]
67 | },
68 | {
69 | "cell_type": "code",
70 | "execution_count": 49,
71 | "metadata": {
72 | "collapsed": false
73 | },
74 | "outputs": [
75 | {
76 | "data": {
77 | "text/plain": [
78 | "array([[ 0.13879034, 0.71300174],\n",
79 | " [ 0.08121322, 0.00393554],\n",
80 | " [ 0.02349471, 0.56677474]])"
81 | ]
82 | },
83 | "execution_count": 49,
84 | "metadata": {},
85 | "output_type": "execute_result"
86 | }
87 | ],
88 | "source": [
89 | "np.random.rand(3, 2) \n",
90 | "# Or np.random.random((3,2))"
91 | ]
92 | },
93 | {
94 | "cell_type": "markdown",
95 | "metadata": {},
96 | "source": [
97 | "Q2. Create an array of shape (1000, 1000) and populate it with random samples from a standard normal distribution. And verify that the mean and standard deviation is close enough to 0 and 1 repectively."
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "execution_count": 42,
103 | "metadata": {
104 | "collapsed": false
105 | },
106 | "outputs": [
107 | {
108 | "name": "stdout",
109 | "output_type": "stream",
110 | "text": [
111 | "-0.00110028519551\n",
112 | "0.999683483393\n"
113 | ]
114 | }
115 | ],
116 | "source": [
117 | "out1 = np.random.randn(1000, 1000)\n",
118 | "out2 = np.random.standard_normal((1000, 1000))\n",
119 | "out3 = np.random.normal(loc=0.0, scale=1.0, size=(1000, 1000))\n",
120 | "assert np.allclose(np.mean(out1), np.mean(out2), atol=0.1)\n",
121 | "assert np.allclose(np.mean(out1), np.mean(out3), atol=0.1)\n",
122 | "assert np.allclose(np.std(out1), np.std(out2), atol=0.1)\n",
123 | "assert np.allclose(np.std(out1), np.std(out3), atol=0.1)\n",
124 | "print np.mean(out3)\n",
125 | "print np.std(out1)\n"
126 | ]
127 | },
128 | {
129 | "cell_type": "markdown",
130 | "metadata": {},
131 | "source": [
132 | "Q3. Create an array of shape (3, 2) and populate it with random integers ranging from 0 to 3 (inclusive) from a discrete uniform distribution."
133 | ]
134 | },
135 | {
136 | "cell_type": "code",
137 | "execution_count": 44,
138 | "metadata": {
139 | "collapsed": false
140 | },
141 | "outputs": [
142 | {
143 | "data": {
144 | "text/plain": [
145 | "array([[1, 3],\n",
146 | " [3, 0],\n",
147 | " [0, 0]])"
148 | ]
149 | },
150 | "execution_count": 44,
151 | "metadata": {},
152 | "output_type": "execute_result"
153 | }
154 | ],
155 | "source": [
156 | "np.random.randint(0, 4, (3, 2))"
157 | ]
158 | },
159 | {
160 | "cell_type": "markdown",
161 | "metadata": {},
162 | "source": [
163 | "Q4. Extract 1 elements from x randomly such that each of them would be associated with probabilities .3, .5, .2. Then print the result 10 times."
164 | ]
165 | },
166 | {
167 | "cell_type": "code",
168 | "execution_count": 58,
169 | "metadata": {
170 | "collapsed": true
171 | },
172 | "outputs": [],
173 | "source": [
174 | "x = [b'3 out of 10', b'5 out of 10', b'2 out of 10']"
175 | ]
176 | },
177 | {
178 | "cell_type": "code",
179 | "execution_count": 60,
180 | "metadata": {
181 | "collapsed": false
182 | },
183 | "outputs": [
184 | {
185 | "name": "stdout",
186 | "output_type": "stream",
187 | "text": [
188 | "2 out of 10\n",
189 | "5 out of 10\n",
190 | "3 out of 10\n",
191 | "5 out of 10\n",
192 | "5 out of 10\n",
193 | "5 out of 10\n",
194 | "2 out of 10\n",
195 | "2 out of 10\n",
196 | "5 out of 10\n",
197 | "5 out of 10\n"
198 | ]
199 | }
200 | ],
201 | "source": [
202 | "for _ in range(10):\n",
203 | " print np.random.choice(x, p=[.3, .5, .2])"
204 | ]
205 | },
206 | {
207 | "cell_type": "markdown",
208 | "metadata": {},
209 | "source": [
210 | "Q5. Extract 3 different integers from 0 to 9 randomly with the same probabilities."
211 | ]
212 | },
213 | {
214 | "cell_type": "code",
215 | "execution_count": 66,
216 | "metadata": {
217 | "collapsed": false
218 | },
219 | "outputs": [
220 | {
221 | "data": {
222 | "text/plain": [
223 | "array([5, 4, 0])"
224 | ]
225 | },
226 | "execution_count": 66,
227 | "metadata": {},
228 | "output_type": "execute_result"
229 | }
230 | ],
231 | "source": [
232 | "np.random.choice(10, 3, replace=False)"
233 | ]
234 | },
235 | {
236 | "cell_type": "markdown",
237 | "metadata": {},
238 | "source": [
239 | "## Permutations"
240 | ]
241 | },
242 | {
243 | "cell_type": "markdown",
244 | "metadata": {},
245 | "source": [
246 | "Q6. Shuffle numbers between 0 and 9 (inclusive)."
247 | ]
248 | },
249 | {
250 | "cell_type": "code",
251 | "execution_count": 86,
252 | "metadata": {
253 | "collapsed": false
254 | },
255 | "outputs": [
256 | {
257 | "name": "stdout",
258 | "output_type": "stream",
259 | "text": [
260 | "[2 3 8 4 5 1 0 6 9 7]\n"
261 | ]
262 | }
263 | ],
264 | "source": [
265 | "x = np.arange(10)\n",
266 | "np.random.shuffle(x)\n",
267 | "print x"
268 | ]
269 | },
270 | {
271 | "cell_type": "code",
272 | "execution_count": 88,
273 | "metadata": {
274 | "collapsed": false
275 | },
276 | "outputs": [
277 | {
278 | "name": "stdout",
279 | "output_type": "stream",
280 | "text": [
281 | "[5 2 7 4 1 0 6 8 9 3]\n"
282 | ]
283 | }
284 | ],
285 | "source": [
286 | "# Or\n",
287 | "print np.random.permutation(10)"
288 | ]
289 | },
290 | {
291 | "cell_type": "markdown",
292 | "metadata": {},
293 | "source": [
294 | "## Random generator"
295 | ]
296 | },
297 | {
298 | "cell_type": "markdown",
299 | "metadata": {},
300 | "source": [
301 | "Q7. Assign number 10 to the seed of the random generator so that you can get the same value next time."
302 | ]
303 | },
304 | {
305 | "cell_type": "code",
306 | "execution_count": 91,
307 | "metadata": {
308 | "collapsed": true
309 | },
310 | "outputs": [],
311 | "source": [
312 | "np.random.seed(10)"
313 | ]
314 | }
315 | ],
316 | "metadata": {
317 | "kernelspec": {
318 | "display_name": "Python 2",
319 | "language": "python",
320 | "name": "python2"
321 | },
322 | "language_info": {
323 | "codemirror_mode": {
324 | "name": "ipython",
325 | "version": 2
326 | },
327 | "file_extension": ".py",
328 | "mimetype": "text/x-python",
329 | "name": "python",
330 | "nbconvert_exporter": "python",
331 | "pygments_lexer": "ipython2",
332 | "version": "2.7.10"
333 | }
334 | },
335 | "nbformat": 4,
336 | "nbformat_minor": 0
337 | }
338 |
--------------------------------------------------------------------------------
/3-rnns/data/names/German.txt:
--------------------------------------------------------------------------------
1 | Abbing
2 | Abel
3 | Abeln
4 | Abt
5 | Achilles
6 | Achterberg
7 | Acker
8 | Ackermann
9 | Adam
10 | Adenauer
11 | Adler
12 | Adlersflügel
13 | Aeschelman
14 | Albert
15 | Albrecht
16 | Aleshire
17 | Aleshite
18 | Althaus
19 | Amsel
20 | Andres
21 | Armbrüster
22 | Armbruster
23 | Artz
24 | Aue
25 | Auer
26 | Augustin
27 | Aust
28 | Autenburg
29 | Auttenberg
30 | Baasch
31 | Bach
32 | Bachmeier
33 | Bäcker
34 | Bader
35 | Bähr
36 | Bambach
37 | Bauer
38 | Bauers
39 | Baum
40 | Baumann
41 | Baumbach
42 | Baumgärtner
43 | Baumgartner
44 | Baumhauer
45 | Bayer
46 | Beck
47 | Becke
48 | Beckenbauer
49 | Becker
50 | Beckert
51 | Behrend
52 | Behrends
53 | Beitel
54 | Beltz
55 | Benn
56 | Berg
57 | Berger
58 | Bergfalk
59 | Beringer
60 | Bernat
61 | Best
62 | Beutel
63 | Beyer
64 | Beyersdorf
65 | Bieber
66 | Biermann
67 | Bischoffs
68 | Blau
69 | Blecher
70 | Bleier
71 | Blumenthal
72 | Blumstein
73 | Bocker
74 | Boehler
75 | Boer
76 | Boesch
77 | Böhler
78 | Böhm
79 | Böhme
80 | Böhmer
81 | Bohn
82 | Borchard
83 | Bösch
84 | Bosch
85 | Böttcher
86 | Brahms
87 | Brand
88 | Brandt
89 | Brant
90 | Brauer
91 | Braun
92 | Braune
93 | Breiner
94 | Breisacher
95 | Breitbarth
96 | Bretz
97 | Brinkerhoff
98 | Brodbeck
99 | Brose
100 | Brotz
101 | Bruhn
102 | Brun
103 | Brune
104 | Buchholz
105 | Buckholtz
106 | Buhr
107 | Bumgarner
108 | Burgstaller
109 | Busch
110 | Carver
111 | Chevrolet
112 | Cline
113 | Dahl
114 | Denzel
115 | Derrick
116 | Diefenbach
117 | Dieter
118 | Dietrich
119 | Dirchs
120 | Dittmar
121 | Dohman
122 | Drechsler
123 | Dreher
124 | Dreschner
125 | Dresdner
126 | Dressler
127 | Duerr
128 | Dunkle
129 | Dunst
130 | Dürr
131 | Eberhardt
132 | Ebner
133 | Ebner
134 | Eckstein
135 | Egger
136 | Eichel
137 | Eilerts
138 | Engel
139 | Enns
140 | Esser
141 | Essert
142 | Everhart
143 | Fabel
144 | Faerber
145 | Falk
146 | Falkenrath
147 | Färber
148 | Fashingbauer
149 | Faust
150 | Feigenbaum
151 | Feld
152 | Feldt
153 | Fenstermacher
154 | Fertig
155 | Fiedler
156 | Fischer
157 | Flater
158 | Fleischer
159 | Foerstner
160 | Forst
161 | Förstner
162 | Foth
163 | Frank
164 | Franke
165 | Frei
166 | Freud
167 | Freudenberger
168 | Freund
169 | Fried
170 | Friedrich
171 | Fromm
172 | Frost
173 | Fuchs
174 | Fuhrmann
175 | Fürst
176 | Fux
177 | Gabler
178 | Gaertner
179 | Garb
180 | Garber
181 | Gärtner
182 | Garver
183 | Gass
184 | Gehrig
185 | Gehring
186 | Geier
187 | Geiger
188 | Geisler
189 | Geissler
190 | Geiszler
191 | Gensch
192 | Gerber
193 | Gerhard
194 | Gerhardt
195 | Gerig
196 | Gerst
197 | Gerstle
198 | Gerver
199 | Giehl
200 | Giese
201 | Glöckner
202 | Goebel
203 | Goldschmidt
204 | Gorman
205 | Gott
206 | Gotti
207 | Gottlieb
208 | Gottschalk
209 | Graner
210 | Greenberg
211 | Groos
212 | Gros
213 | Gross
214 | Groß
215 | Große
216 | Grosse
217 | Größel
218 | Großel
219 | Großer
220 | Grosser
221 | Grosz
222 | Grünewald
223 | Günther
224 | Gunther
225 | Gutermuth
226 | Gwerder
227 | Haas
228 | Haase
229 | Haber
230 | Habich
231 | Habicht
232 | Hafner
233 | Hahn
234 | Hall
235 | Halle
236 | Harman
237 | Hartmann
238 | Hase
239 | Hasek
240 | Hasenkamp
241 | Hass
242 | Hauer
243 | Haupt
244 | Hausler
245 | Havener
246 | Heidrich
247 | Heinrich
248 | Heinrichs
249 | Heintze
250 | Hellewege
251 | Heppenheimer
252 | Herbert
253 | Hermann
254 | Herrmann
255 | Herschel
256 | Hertz
257 | Hildebrand
258 | Hinrichs
259 | Hintzen
260 | Hirsch
261 | Hoch
262 | Hochberg
263 | Hoefler
264 | Hofer
265 | Hoffman
266 | Hoffmann
267 | Höfler
268 | Hofmann
269 | Hofmeister
270 | Holst
271 | Holtzer
272 | Hölzer
273 | Holzer
274 | Holzknecht
275 | Holzmann
276 | Hoover
277 | Horn
278 | Horn
279 | Horowitz
280 | Houk
281 | Hüber
282 | Huber
283 | Huff
284 | Huffman
285 | Huffmann
286 | Hummel
287 | Hummel
288 | Hutmacher
289 | Ingersleben
290 | Jaeger
291 | Jäger
292 | Jager
293 | Jans
294 | Janson
295 | Janz
296 | Jollenbeck
297 | Jordan
298 | Jund
299 | Jung
300 | Junge
301 | Kahler
302 | Kaiser
303 | Kalb
304 | Kalbfleisch
305 | Kappel
306 | Karl
307 | Kaspar
308 | Kassmeyer
309 | Kästner
310 | Katz
311 | Kaube
312 | Käufer
313 | Kaufer
314 | Kauffmann
315 | Kaufman
316 | Keil
317 | Keller
318 | Kempf
319 | Kerner
320 | Kerper
321 | Kerwar
322 | Kerwer
323 | Kiefer
324 | Kiefer
325 | Kirchner
326 | Kistler
327 | Kistner
328 | Kleid
329 | Klein
330 | Klossner
331 | Knef
332 | Kneib
333 | Kneller
334 | Knepp
335 | Knochenmus
336 | Knopf
337 | Knopp
338 | Koch
339 | Kock
340 | Koenig
341 | Koenigsmann
342 | Köhl
343 | Kohl
344 | Köhler
345 | Kohler
346 | Kolbe
347 | König
348 | Königsmann
349 | Kopp
350 | Kraemer
351 | Krämer
352 | Kramer
353 | Krantz
354 | Kranz
355 | Kraus
356 | Krause
357 | Krauss
358 | Krauß
359 | Krebs
360 | Kröger
361 | Kron
362 | Kruckel
363 | Krüger
364 | Krüger
365 | Kruger
366 | Kruse
367 | Kruse
368 | Küchler
369 | Kuhn
370 | Kundert
371 | Kunkel
372 | Kunkle
373 | Kuntz
374 | Kunze
375 | Kurzmann
376 | Laberenz
377 | Lafrentz
378 | Lafrenz
379 | Landau
380 | Lang
381 | Lange
382 | Langenberg
383 | Langer
384 | Larenz
385 | Laurenz
386 | Lauritz
387 | Lawerenz
388 | Lawrenz
389 | Lehmann
390 | Lehrer
391 | Leitner
392 | Leitz
393 | Leitzke
394 | Lenz
395 | Leverenz
396 | Lewerentz
397 | Lewerenz
398 | Lichtenberg
399 | Lieberenz
400 | Linden
401 | Loewe
402 | Lohrenz
403 | Lorentz
404 | Lorenz
405 | Lorenzen
406 | Loris
407 | Loritz
408 | Löwe
409 | Ludwig
410 | Luther
411 | Maas
412 | Maier
413 | Mandel
414 | Mann
415 | Markwardt
416 | Marquardt
417 | Marquering
418 | Marquerink
419 | Martell
420 | Martin
421 | Martz
422 | Mas
423 | Maurer
424 | Maus
425 | Mayer
426 | Meier
427 | Mein
428 | Meindl
429 | Meinhardt
430 | Meisner
431 | Meissner
432 | Melsbach
433 | Mendel
434 | Mendelsohn
435 | Mendelssohn
436 | Messer
437 | Messerli
438 | Messmann
439 | Messner
440 | Metz
441 | Metz
442 | Metzger
443 | Meyer
444 | Michel
445 | Mohren
446 | Möller
447 | Morgenstern
448 | Moser
449 | Mueller
450 | Muhlfeld
451 | Müller
452 | Nagel
453 | Neuman
454 | Neumann
455 | Nuremberg
456 | Nussbaum
457 | Nussenbaum
458 | Oberst
459 | Oelberg
460 | Ohme
461 | Oliver
462 | Oppenheimer
463 | Ott
464 | Otto
465 | Oursler
466 | Pahlke
467 | Papke
468 | Papp
469 | Paternoster
470 | Paul
471 | Paulis
472 | Pawlitzki
473 | Penzig
474 | Peter
475 | Peters
476 | Pfaff
477 | Pfenning
478 | Plank
479 | Pletcher
480 | Porsche
481 | Portner
482 | Prinz
483 | Protz
484 | Rademacher
485 | Rademaker
486 | Rapp
487 | Raske
488 | Raskob
489 | Raskop
490 | Raskoph
491 | Regenbogen
492 | Reier
493 | Reiher
494 | Reiter
495 | Rettig
496 | Reuter
497 | Reuter
498 | Richard
499 | Richter
500 | Rier
501 | Riese
502 | Ritter
503 | Rose
504 | Rosenberg
505 | Rosenberger
506 | Rosenfeld
507 | Rot
508 | Roth
509 | Rothbauer
510 | Rothenberg
511 | Rothschild
512 | Sachs
513 | Saller
514 | Saller
515 | Salomon
516 | Salzwedel
517 | Samuel
518 | Sander
519 | Sauber
520 | Schäfer
521 | Scheer
522 | Scheinberg
523 | Schenck
524 | Schermer
525 | Schindler
526 | Schirmer
527 | Schlender
528 | Schlimme
529 | Schlusser
530 | Schmeling
531 | Schmid
532 | Schmidt
533 | Schmitt
534 | Schmitz
535 | Schneider
536 | Schnoor
537 | Schnur
538 | Schoettmer
539 | Schräder
540 | Schrader
541 | Schreck
542 | Schreier
543 | Schröder
544 | Schröder
545 | Schroeder
546 | Schroeter
547 | Schröter
548 | Schubert
549 | Schuchard
550 | Schuchardt
551 | Schuchert
552 | Schuhart
553 | Schuhmacher
554 | Schuler
555 | Schult
556 | Schulte
557 | Schultes
558 | Schultheis
559 | Schultheiss
560 | Schultheiß
561 | Schultz
562 | Schultze
563 | Schulz
564 | Schulze
565 | Schumacher
566 | Schuster
567 | Schuttmann
568 | Schwangau
569 | Schwartz
570 | Schwarz
571 | Schwarzenegger
572 | Schwenke
573 | Schwinghammer
574 | Seelenfreund
575 | Seidel
576 | Senft
577 | Senft
578 | Sheinfeld
579 | Shriver
580 | Siegel
581 | Siegel
582 | Siekert
583 | Siemon
584 | Silverstein
585 | Simen
586 | Simmon
587 | Simon
588 | Simons
589 | Siskin
590 | Siskind
591 | Sitz
592 | Sitz
593 | Slusser
594 | Solberg
595 | Sommer
596 | Sommer
597 | Sommer
598 | Sommer
599 | Sonnen
600 | Sorg
601 | Sorge
602 | Spannagel
603 | Specht
604 | Spellmeyer
605 | Spitznogle
606 | Sponaugle
607 | Stark
608 | Stauss
609 | Steen
610 | Steffen
611 | Stein
612 | Steinmann
613 | Stenger
614 | Sternberg
615 | Steube
616 | Steuben
617 | Stieber
618 | Stoppelbein
619 | Stoppelbein
620 | Strand
621 | Straub
622 | Strobel
623 | Strohkirch
624 | Stroman
625 | Stuber
626 | Stueck
627 | Stumpf
628 | Sturm
629 | Suess
630 | Sulzbach
631 | Swango
632 | Switzer
633 | Tangeman
634 | Tanzer
635 | Teufel
636 | Tiedeman
637 | Tifft
638 | Tillens
639 | Tobias
640 | Tolkien
641 | Tresler
642 | Tritten
643 | Trumbauer
644 | Tschida
645 | Unkle
646 | Unruh
647 | Unterbrink
648 | Ursler
649 | Vann
650 | Van tonder
651 | Vieth
652 | Vogel
653 | Vogt
654 | Vogts
655 | Voigt
656 | Voigts
657 | Volk
658 | Voll
659 | Von brandt
660 | Von essen
661 | Von grimmelshausen
662 | Von ingersleben
663 | Vonnegut
664 | Von wegberg
665 | Voss
666 | Voß
667 | Wägner
668 | Wagner
669 | Wähner
670 | Wahner
671 | Waldfogel
672 | Waldvogel
673 | Walkenhorst
674 | Walter
675 | Walther
676 | Waltz
677 | Wang
678 | Warner
679 | Waxweiler
680 | Weber
681 | Wechsler
682 | Wedekind
683 | Weeber
684 | Wegener
685 | Wegner
686 | Wehner
687 | Wehunt
688 | Weigand
689 | Weiman
690 | Weiner
691 | Weiss
692 | Weiß
693 | Welter
694 | Wendel
695 | Wendell
696 | Werner
697 | Wernher
698 | West
699 | Westerberg
700 | Wetterman
701 | Wetzel
702 | Wexler
703 | Wieck
704 | Wiegand
705 | Wildgrube
706 | Winter
707 | Winther
708 | Winther
709 | Wirner
710 | Wirnhier
711 | Wirt
712 | Wirth
713 | Wolf
714 | Wolff
715 | Wolter
716 | Wörner
717 | Wörnhör
718 | Wruck
719 | Wyman
720 | Xylander
721 | Zellweger
722 | Zilberschlag
723 | Zimmerman
724 | Zimmermann
725 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Italian.txt:
--------------------------------------------------------------------------------
1 | Abandonato
2 | Abatangelo
3 | Abatantuono
4 | Abate
5 | Abategiovanni
6 | Abatescianni
7 | Abbà
8 | Abbadelli
9 | Abbascia
10 | Abbatangelo
11 | Abbatantuono
12 | Abbate
13 | Abbatelli
14 | Abbaticchio
15 | Abbiati
16 | Abbracciabene
17 | Abbracciabeni
18 | Abelli
19 | Abelló
20 | Abrami
21 | Abramo
22 | Acardi
23 | Accardi
24 | Accardo
25 | Acciai
26 | Acciaio
27 | Acciaioli
28 | Acconci
29 | Acconcio
30 | Accorsi
31 | Accorso
32 | Accosi
33 | Accursio
34 | Acerbi
35 | Acone
36 | Aconi
37 | Acqua
38 | Acquafredda
39 | Acquarone
40 | Acquati
41 | Adalardi
42 | Adami
43 | Adamo
44 | Adamoli
45 | Addario
46 | Adelardi
47 | Adessi
48 | Adimari
49 | Adriatico
50 | Affini
51 | Africani
52 | Africano
53 | Agani
54 | Aggi
55 | Aggio
56 | Agli
57 | Agnelli
58 | Agnellutti
59 | Agnusdei
60 | Agosti
61 | Agostini
62 | Agresta
63 | Agrioli
64 | Aiello
65 | Aiolfi
66 | Airaldi
67 | Airò
68 | Aita
69 | Ajello
70 | Alagona
71 | Alamanni
72 | Albanesi
73 | Albani
74 | Albano
75 | Alberghi
76 | Alberghini
77 | Alberici
78 | Alberighi
79 | Albero
80 | Albini
81 | Albricci
82 | Albrici
83 | Alcheri
84 | Aldebrandi
85 | Alderisi
86 | Alduino
87 | Alemagna
88 | Aleppo
89 | Alesci
90 | Alescio
91 | Alesi
92 | Alesini
93 | Alesio
94 | Alessandri
95 | Alessi
96 | Alfero
97 | Aliberti
98 | Alinari
99 | Aliprandi
100 | Allegri
101 | Allegro
102 | Alò
103 | Aloia
104 | Aloisi
105 | Altamura
106 | Altimari
107 | Altoviti
108 | Alunni
109 | Amadei
110 | Amadori
111 | Amalberti
112 | Amantea
113 | Amato
114 | Amatore
115 | Ambrogi
116 | Ambrosi
117 | Amello
118 | Amerighi
119 | Amoretto
120 | Angioli
121 | Ansaldi
122 | Anselmetti
123 | Anselmi
124 | Antonelli
125 | Antonini
126 | Antonino
127 | Aquila
128 | Aquino
129 | Arbore
130 | Ardiccioni
131 | Ardizzone
132 | Ardovini
133 | Arena
134 | Aringheri
135 | Arlotti
136 | Armani
137 | Armati
138 | Armonni
139 | Arnolfi
140 | Arnoni
141 | Arrighetti
142 | Arrighi
143 | Arrigucci
144 | Aucciello
145 | Azzarà
146 | Baggi
147 | Baggio
148 | Baglio
149 | Bagni
150 | Bagnoli
151 | Balboni
152 | Baldi
153 | Baldini
154 | Baldinotti
155 | Baldovini
156 | Bandini
157 | Bandoni
158 | Barbieri
159 | Barone
160 | Barsetti
161 | Bartalotti
162 | Bartolomei
163 | Bartolomeo
164 | Barzetti
165 | Basile
166 | Bassanelli
167 | Bassani
168 | Bassi
169 | Basso
170 | Basurto
171 | Battaglia
172 | Bazzoli
173 | Bellandi
174 | Bellandini
175 | Bellincioni
176 | Bellini
177 | Bello
178 | Bellomi
179 | Belloni
180 | Belluomi
181 | Belmonte
182 | Bencivenni
183 | Benedetti
184 | Benenati
185 | Benetton
186 | Benini
187 | Benivieni
188 | Benvenuti
189 | Berardi
190 | Bergamaschi
191 | Berti
192 | Bertolini
193 | Biancardi
194 | Bianchi
195 | Bicchieri
196 | Biondi
197 | Biondo
198 | Boerio
199 | Bologna
200 | Bondesan
201 | Bonomo
202 | Borghi
203 | Borgnino
204 | Borgogni
205 | Bosco
206 | Bove
207 | Bovér
208 | Boveri
209 | Brambani
210 | Brambilla
211 | Breda
212 | Brioschi
213 | Brivio
214 | Brunetti
215 | Bruno
216 | Buffone
217 | Bulgarelli
218 | Bulgari
219 | Buonarroti
220 | Busto
221 | Caiazzo
222 | Caito
223 | Caivano
224 | Calabrese
225 | Calligaris
226 | Campana
227 | Campo
228 | Cantu
229 | Capello
230 | Capello
231 | Capello
232 | Capitani
233 | Carbone
234 | Carboni
235 | Carideo
236 | Carlevaro
237 | Caro
238 | Carracci
239 | Carrara
240 | Caruso
241 | Cassano
242 | Castro
243 | Catalano
244 | Cattaneo
245 | Cavalcante
246 | Cavallo
247 | Cingolani
248 | Cino
249 | Cipriani
250 | Cisternino
251 | Coiro
252 | Cola
253 | Colombera
254 | Colombo
255 | Columbo
256 | Como
257 | Como
258 | Confortola
259 | Conti
260 | Corna
261 | Corti
262 | Corvi
263 | Costa
264 | Costantini
265 | Costanzo
266 | Cracchiolo
267 | Cremaschi
268 | Cremona
269 | Cremonesi
270 | Crespo
271 | Croce
272 | Crocetti
273 | Cucinotta
274 | Cuocco
275 | Cuoco
276 | D'ambrosio
277 | Damiani
278 | D'amore
279 | D'angelo
280 | D'antonio
281 | De angelis
282 | De campo
283 | De felice
284 | De filippis
285 | De fiore
286 | De laurentis
287 | De luca
288 | De palma
289 | De rege
290 | De santis
291 | De vitis
292 | Di antonio
293 | Di caprio
294 | Di mercurio
295 | Dinapoli
296 | Dioli
297 | Di pasqua
298 | Di pietro
299 | Di stefano
300 | Donati
301 | D'onofrio
302 | Drago
303 | Durante
304 | Elena
305 | Episcopo
306 | Ermacora
307 | Esposito
308 | Evangelista
309 | Fabbri
310 | Fabbro
311 | Falco
312 | Faraldo
313 | Farina
314 | Farro
315 | Fattore
316 | Fausti
317 | Fava
318 | Favero
319 | Fermi
320 | Ferrara
321 | Ferrari
322 | Ferraro
323 | Ferrero
324 | Ferro
325 | Fierro
326 | Filippi
327 | Fini
328 | Fiore
329 | Fiscella
330 | Fiscella
331 | Fonda
332 | Fontana
333 | Fortunato
334 | Franco
335 | Franzese
336 | Furlan
337 | Gabrielli
338 | Gagliardi
339 | Gallo
340 | Ganza
341 | Garfagnini
342 | Garofalo
343 | Gaspari
344 | Gatti
345 | Genovese
346 | Gentile
347 | Germano
348 | Giannino
349 | Gimondi
350 | Giordano
351 | Gismondi
352 | Giùgovaz
353 | Giunta
354 | Goretti
355 | Gori
356 | Greco
357 | Grillo
358 | Grimaldi
359 | Gronchi
360 | Guarneri
361 | Guerra
362 | Guerriero
363 | Guidi
364 | Guttuso
365 | Idoni
366 | Innocenti
367 | Labriola
368 | Làconi
369 | Laganà
370 | Lagomarsìno
371 | Lagorio
372 | Laguardia
373 | Lama
374 | Lamberti
375 | Lamon
376 | Landi
377 | Lando
378 | Landolfi
379 | Laterza
380 | Laurito
381 | Lazzari
382 | Lecce
383 | Leccese
384 | Leggièri
385 | Lèmmi
386 | Leone
387 | Leoni
388 | Lippi
389 | Locatelli
390 | Lombardi
391 | Longo
392 | Lupo
393 | Luzzatto
394 | Maestri
395 | Magro
396 | Mancini
397 | Manco
398 | Mancuso
399 | Manfredi
400 | Manfredonia
401 | Mantovani
402 | Marchegiano
403 | Marchesi
404 | Marchetti
405 | Marchioni
406 | Marconi
407 | Mari
408 | Maria
409 | Mariani
410 | Marino
411 | Marmo
412 | Martelli
413 | Martinelli
414 | Masi
415 | Masin
416 | Mazza
417 | Merlo
418 | Messana
419 | Micheli
420 | Milani
421 | Milano
422 | Modugno
423 | Mondadori
424 | Mondo
425 | Montagna
426 | Montana
427 | Montanari
428 | Monte
429 | Monti
430 | Morandi
431 | Morello
432 | Moretti
433 | Morra
434 | Moschella
435 | Mosconi
436 | Motta
437 | Muggia
438 | Muraro
439 | Murgia
440 | Murtas
441 | Nacar
442 | Naggi
443 | Naggia
444 | Naldi
445 | Nana
446 | Nani
447 | Nanni
448 | Nannini
449 | Napoleoni
450 | Napoletani
451 | Napoliello
452 | Nardi
453 | Nardo
454 | Nardovino
455 | Nasato
456 | Nascimbene
457 | Nascimbeni
458 | Natale
459 | Nave
460 | Nazario
461 | Necchi
462 | Negri
463 | Negrini
464 | Nelli
465 | Nenci
466 | Nepi
467 | Neri
468 | Neroni
469 | Nervetti
470 | Nervi
471 | Nespola
472 | Nicastro
473 | Nicchi
474 | Nicodemo
475 | Nicolai
476 | Nicolosi
477 | Nicosia
478 | Nicotera
479 | Nieddu
480 | Nieri
481 | Nigro
482 | Nisi
483 | Nizzola
484 | Noschese
485 | Notaro
486 | Notoriano
487 | Oberti
488 | Oberto
489 | Ongaro
490 | Orlando
491 | Orsini
492 | Pace
493 | Padovan
494 | Padovano
495 | Pagani
496 | Pagano
497 | Palladino
498 | Palmisano
499 | Palumbo
500 | Panzavecchia
501 | Parisi
502 | Parma
503 | Parodi
504 | Parri
505 | Parrino
506 | Passerini
507 | Pastore
508 | Paternoster
509 | Pavesi
510 | Pavone
511 | Pavoni
512 | Pecora
513 | Pedrotti
514 | Pellegrino
515 | Perugia
516 | Pesaresi
517 | Pesaro
518 | Pesce
519 | Petri
520 | Pherigo
521 | Piazza
522 | Piccirillo
523 | Piccoli
524 | Pierno
525 | Pietri
526 | Pini
527 | Piovene
528 | Piraino
529 | Pisani
530 | Pittaluga
531 | Poggi
532 | Poggio
533 | Poletti
534 | Pontecorvo
535 | Portelli
536 | Porto
537 | Portoghese
538 | Potenza
539 | Pozzi
540 | Profeta
541 | Prosdocimi
542 | Provenza
543 | Provenzano
544 | Pugliese
545 | Quaranta
546 | Quattrocchi
547 | Ragno
548 | Raimondi
549 | Rais
550 | Rana
551 | Raneri
552 | Rao
553 | Rapallino
554 | Ratti
555 | Ravenna
556 | Ré
557 | Ricchetti
558 | Ricci
559 | Riggi
560 | Righi
561 | Rinaldi
562 | Riva
563 | Rizzo
564 | Robustelli
565 | Rocca
566 | Rocchi
567 | Rocco
568 | Roma
569 | Roma
570 | Romagna
571 | Romagnoli
572 | Romano
573 | Romano
574 | Romero
575 | Roncalli
576 | Ronchi
577 | Rosa
578 | Rossi
579 | Rossini
580 | Rotolo
581 | Rovigatti
582 | Ruggeri
583 | Russo
584 | Rustici
585 | Ruzzier
586 | Sabbadin
587 | Sacco
588 | Sala
589 | Salomon
590 | Salucci
591 | Salvaggi
592 | Salvai
593 | Salvail
594 | Salvatici
595 | Salvay
596 | Sanna
597 | Sansone
598 | Santini
599 | Santoro
600 | Sapienti
601 | Sarno
602 | Sarti
603 | Sartini
604 | Sarto
605 | Savona
606 | Scarpa
607 | Scarsi
608 | Scavo
609 | Sciacca
610 | Sciacchitano
611 | Sciarra
612 | Scordato
613 | Scotti
614 | Scutese
615 | Sebastiani
616 | Sebastino
617 | Segreti
618 | Selmone
619 | Selvaggio
620 | Serafin
621 | Serafini
622 | Serpico
623 | Sessa
624 | Sgro
625 | Siena
626 | Silvestri
627 | Sinagra
628 | Sinagra
629 | Soldati
630 | Somma
631 | Sordi
632 | Soriano
633 | Sorrentino
634 | Spada
635 | Spanò
636 | Sparacello
637 | Speziale
638 | Spini
639 | Stabile
640 | Stablum
641 | Stilo
642 | Sultana
643 | Tafani
644 | Tamàro
645 | Tamboia
646 | Tanzi
647 | Tarantino
648 | Taverna
649 | Tedesco
650 | Terranova
651 | Terzi
652 | Tessaro
653 | Testa
654 | Tiraboschi
655 | Tivoli
656 | Todaro
657 | Toloni
658 | Tornincasa
659 | Toselli
660 | Tosetti
661 | Tosi
662 | Tosto
663 | Trapani
664 | Traversa
665 | Traversi
666 | Traversini
667 | Traverso
668 | Trucco
669 | Trudu
670 | Tumicelli
671 | Turati
672 | Turchi
673 | Uberti
674 | Uccello
675 | Uggeri
676 | Ughi
677 | Ungaretti
678 | Ungaro
679 | Vacca
680 | Vaccaro
681 | Valenti
682 | Valentini
683 | Valerio
684 | Varano
685 | Ventimiglia
686 | Ventura
687 | Verona
688 | Veronesi
689 | Vescovi
690 | Vespa
691 | Vestri
692 | Vicario
693 | Vico
694 | Vigo
695 | Villa
696 | Vinci
697 | Vinci
698 | Viola
699 | Vitali
700 | Viteri
701 | Voltolini
702 | Zambrano
703 | Zanetti
704 | Zangari
705 | Zappa
706 | Zeni
707 | Zini
708 | Zino
709 | Zunino
710 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/11-sorting-searching-counting.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Soring, searching, and counting"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 1,
13 | "metadata": {
14 | "collapsed": true
15 | },
16 | "outputs": [],
17 | "source": [
18 | "import numpy as np"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 2,
24 | "metadata": {},
25 | "outputs": [
26 | {
27 | "data": {
28 | "text/plain": [
29 | "'1.11.2'"
30 | ]
31 | },
32 | "execution_count": 2,
33 | "metadata": {},
34 | "output_type": "execute_result"
35 | }
36 | ],
37 | "source": [
38 | "np.__version__"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": 3,
44 | "metadata": {
45 | "collapsed": true
46 | },
47 | "outputs": [],
48 | "source": [
49 | "author = 'kyubyong. longinglove@nate.com'"
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "## Sorting"
57 | ]
58 | },
59 | {
60 | "cell_type": "markdown",
61 | "metadata": {},
62 | "source": [
63 | "Q1. Sort x along the second axis."
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": 11,
69 | "metadata": {},
70 | "outputs": [
71 | {
72 | "name": "stdout",
73 | "output_type": "stream",
74 | "text": [
75 | "[[1 4]\n",
76 | " [1 3]]\n"
77 | ]
78 | }
79 | ],
80 | "source": [
81 | "x = np.array([[1,4],[3,1]])\n"
82 | ]
83 | },
84 | {
85 | "cell_type": "markdown",
86 | "metadata": {},
87 | "source": [
88 | "Q2. Sort pairs of surnames and first names and return their indices. (first by surname, then by name)."
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": 13,
94 | "metadata": {},
95 | "outputs": [
96 | {
97 | "name": "stdout",
98 | "output_type": "stream",
99 | "text": [
100 | "[1 2 0]\n"
101 | ]
102 | }
103 | ],
104 | "source": [
105 | "surnames = ('Hertz', 'Galilei', 'Hertz')\n",
106 | "first_names = ('Heinrich', 'Galileo', 'Gustav')\n"
107 | ]
108 | },
109 | {
110 | "cell_type": "markdown",
111 | "metadata": {},
112 | "source": [
113 | "Q3. Get the indices that would sort x along the second axis."
114 | ]
115 | },
116 | {
117 | "cell_type": "code",
118 | "execution_count": 17,
119 | "metadata": {},
120 | "outputs": [
121 | {
122 | "name": "stdout",
123 | "output_type": "stream",
124 | "text": [
125 | "[[0 1]\n",
126 | " [1 0]]\n"
127 | ]
128 | }
129 | ],
130 | "source": [
131 | "x = np.array([[1,4],[3,1]])\n"
132 | ]
133 | },
134 | {
135 | "cell_type": "markdown",
136 | "metadata": {},
137 | "source": [
138 | "Q4. Create an array such that its fifth element would be the same as the element of sorted x, and it divide other elements by their value."
139 | ]
140 | },
141 | {
142 | "cell_type": "code",
143 | "execution_count": 48,
144 | "metadata": {},
145 | "outputs": [
146 | {
147 | "name": "stdout",
148 | "output_type": "stream",
149 | "text": [
150 | "x = [5 1 6 3 9 8 2 7 4 0]\n",
151 | "\n",
152 | "Check the fifth element of this new array is 5, the first four elements are all smaller than 5, and 6th through the end are bigger than 5\n",
153 | "[2 0 4 3 1 5 8 7 6 9]\n"
154 | ]
155 | }
156 | ],
157 | "source": [
158 | "x = np.random.permutation(10)\n",
159 | "print \"x =\", x\n"
160 | ]
161 | },
162 | {
163 | "cell_type": "markdown",
164 | "metadata": {},
165 | "source": [
166 | "Q5. Create the indices of an array such that its third element would be the same as the element of sorted x, and it divide other elements by their value."
167 | ]
168 | },
169 | {
170 | "cell_type": "code",
171 | "execution_count": 56,
172 | "metadata": {},
173 | "outputs": [
174 | {
175 | "name": "stdout",
176 | "output_type": "stream",
177 | "text": [
178 | "x = [2 8 3 7 5 6 4 0 9 1]\n",
179 | "partitioned = [0 1 2 3 4 5 8 6 9 7]\n",
180 | "indices = [0 1 2 3 4 5 8 6 9 7]\n"
181 | ]
182 | }
183 | ],
184 | "source": [
185 | "x = np.random.permutation(10)\n",
186 | "print \"x =\", x\n"
187 | ]
188 | },
189 | {
190 | "cell_type": "markdown",
191 | "metadata": {},
192 | "source": [
193 | "## Searching"
194 | ]
195 | },
196 | {
197 | "cell_type": "markdown",
198 | "metadata": {},
199 | "source": [
200 | "Q6. Get the maximum and minimum values and their indices of x along the second axis."
201 | ]
202 | },
203 | {
204 | "cell_type": "code",
205 | "execution_count": 78,
206 | "metadata": {},
207 | "outputs": [
208 | {
209 | "name": "stdout",
210 | "output_type": "stream",
211 | "text": [
212 | "x = [[0 5 9 8 2]\n",
213 | " [3 7 4 1 6]]\n",
214 | "maximum values = [9 7]\n",
215 | "max indices = [2 1]\n",
216 | "minimum values = [0 1]\n",
217 | "min indices = [0 3]\n"
218 | ]
219 | }
220 | ],
221 | "source": [
222 | "x = np.random.permutation(10).reshape(2, 5)\n",
223 | "print \"x =\", x\n"
224 | ]
225 | },
226 | {
227 | "cell_type": "markdown",
228 | "metadata": {},
229 | "source": [
230 | "Q7. Get the maximum and minimum values and their indices of x along the second axis, ignoring NaNs."
231 | ]
232 | },
233 | {
234 | "cell_type": "code",
235 | "execution_count": 79,
236 | "metadata": {},
237 | "outputs": [
238 | {
239 | "name": "stdout",
240 | "output_type": "stream",
241 | "text": [
242 | "maximum values ignoring NaNs = [ 4. 3.]\n",
243 | "max indices = [1 0]\n",
244 | "minimum values ignoring NaNs = [ 4. 2.]\n",
245 | "min indices = [1 1]\n"
246 | ]
247 | }
248 | ],
249 | "source": [
250 | "x = np.array([[np.nan, 4], [3, 2]])\n"
251 | ]
252 | },
253 | {
254 | "cell_type": "markdown",
255 | "metadata": {},
256 | "source": [
257 | "Q8. Get the values and indices of the elements that are bigger than 2 in x.\n"
258 | ]
259 | },
260 | {
261 | "cell_type": "code",
262 | "execution_count": 113,
263 | "metadata": {},
264 | "outputs": [
265 | {
266 | "name": "stdout",
267 | "output_type": "stream",
268 | "text": [
269 | "Values bigger than 2 = [3 3 5]\n",
270 | "Their indices are (array([0, 1, 1], dtype=int64), array([2, 1, 2], dtype=int64))\n"
271 | ]
272 | }
273 | ],
274 | "source": [
275 | "x = np.array([[1, 2, 3], [1, 3, 5]])\n"
276 | ]
277 | },
278 | {
279 | "cell_type": "markdown",
280 | "metadata": {},
281 | "source": [
282 | "Q9. Get the indices of the elements that are bigger than 2 in the flattend x."
283 | ]
284 | },
285 | {
286 | "cell_type": "code",
287 | "execution_count": 100,
288 | "metadata": {},
289 | "outputs": [
290 | {
291 | "name": "stdout",
292 | "output_type": "stream",
293 | "text": [
294 | "[0 1 2 3 4 5]\n"
295 | ]
296 | }
297 | ],
298 | "source": [
299 | "x = np.array([[1, 2, 3], [1, 3, 5]])\n"
300 | ]
301 | },
302 | {
303 | "cell_type": "markdown",
304 | "metadata": {},
305 | "source": [
306 | "Q10. Check the elements of x and return 0 if it is less than 0, otherwise the element itself."
307 | ]
308 | },
309 | {
310 | "cell_type": "code",
311 | "execution_count": 105,
312 | "metadata": {},
313 | "outputs": [
314 | {
315 | "name": "stdout",
316 | "output_type": "stream",
317 | "text": [
318 | "[[0 0 0]\n",
319 | " [0 0 0]\n",
320 | " [1 2 3]]\n"
321 | ]
322 | }
323 | ],
324 | "source": [
325 | "x = np.arange(-5, 4).reshape(3, 3)\n"
326 | ]
327 | },
328 | {
329 | "cell_type": "markdown",
330 | "metadata": {},
331 | "source": [
332 | "Q11. Get the indices where elements of y should be inserted to x to maintain order."
333 | ]
334 | },
335 | {
336 | "cell_type": "code",
337 | "execution_count": 109,
338 | "metadata": {},
339 | "outputs": [
340 | {
341 | "data": {
342 | "text/plain": [
343 | "array([0, 2, 1, 3], dtype=int64)"
344 | ]
345 | },
346 | "execution_count": 109,
347 | "metadata": {},
348 | "output_type": "execute_result"
349 | }
350 | ],
351 | "source": [
352 | "x = [1, 3, 5, 7, 9]\n",
353 | "y = [0, 4, 2, 6]\n"
354 | ]
355 | },
356 | {
357 | "cell_type": "markdown",
358 | "metadata": {},
359 | "source": [
360 | "## Counting"
361 | ]
362 | },
363 | {
364 | "cell_type": "markdown",
365 | "metadata": {},
366 | "source": [
367 | "Q12. Get the number of nonzero elements in x."
368 | ]
369 | },
370 | {
371 | "cell_type": "code",
372 | "execution_count": 120,
373 | "metadata": {},
374 | "outputs": [
375 | {
376 | "name": "stdout",
377 | "output_type": "stream",
378 | "text": [
379 | "5\n"
380 | ]
381 | }
382 | ],
383 | "source": [
384 | "x = [[0,1,7,0,0],[3,0,0,2,19]]\n"
385 | ]
386 | },
387 | {
388 | "cell_type": "code",
389 | "execution_count": null,
390 | "metadata": {
391 | "collapsed": true
392 | },
393 | "outputs": [],
394 | "source": []
395 | }
396 | ],
397 | "metadata": {
398 | "kernelspec": {
399 | "display_name": "Python 3",
400 | "language": "python",
401 | "name": "python3"
402 | },
403 | "language_info": {
404 | "codemirror_mode": {
405 | "name": "ipython",
406 | "version": 3
407 | },
408 | "file_extension": ".py",
409 | "mimetype": "text/x-python",
410 | "name": "python",
411 | "nbconvert_exporter": "python",
412 | "pygments_lexer": "ipython3",
413 | "version": "3.6.2"
414 | }
415 | },
416 | "nbformat": 4,
417 | "nbformat_minor": 1
418 | }
419 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/Sorting_searching_and_counting_Solutions.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Soring, searching, and counting"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 1,
13 | "metadata": {
14 | "collapsed": true
15 | },
16 | "outputs": [],
17 | "source": [
18 | "import numpy as np"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 2,
24 | "metadata": {
25 | "collapsed": false
26 | },
27 | "outputs": [
28 | {
29 | "data": {
30 | "text/plain": [
31 | "'1.11.2'"
32 | ]
33 | },
34 | "execution_count": 2,
35 | "metadata": {},
36 | "output_type": "execute_result"
37 | }
38 | ],
39 | "source": [
40 | "np.__version__"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": 3,
46 | "metadata": {
47 | "collapsed": true
48 | },
49 | "outputs": [],
50 | "source": [
51 | "author = 'kyubyong. longinglove@nate.com'"
52 | ]
53 | },
54 | {
55 | "cell_type": "markdown",
56 | "metadata": {},
57 | "source": [
58 | "## Sorting"
59 | ]
60 | },
61 | {
62 | "cell_type": "markdown",
63 | "metadata": {},
64 | "source": [
65 | "Q1. Sort x along the second axis."
66 | ]
67 | },
68 | {
69 | "cell_type": "code",
70 | "execution_count": 11,
71 | "metadata": {
72 | "collapsed": false
73 | },
74 | "outputs": [
75 | {
76 | "name": "stdout",
77 | "output_type": "stream",
78 | "text": [
79 | "[[1 4]\n",
80 | " [1 3]]\n"
81 | ]
82 | }
83 | ],
84 | "source": [
85 | "x = np.array([[1,4],[3,1]])\n",
86 | "out = np.sort(x, axis=1)\n",
87 | "x.sort(axis=1)\n",
88 | "assert np.array_equal(out, x)\n",
89 | "print out"
90 | ]
91 | },
92 | {
93 | "cell_type": "markdown",
94 | "metadata": {},
95 | "source": [
96 | "Q2. Sort pairs of surnames and first names and return their indices. (first by surname, then by name)."
97 | ]
98 | },
99 | {
100 | "cell_type": "code",
101 | "execution_count": 13,
102 | "metadata": {
103 | "collapsed": false
104 | },
105 | "outputs": [
106 | {
107 | "name": "stdout",
108 | "output_type": "stream",
109 | "text": [
110 | "[1 2 0]\n"
111 | ]
112 | }
113 | ],
114 | "source": [
115 | "surnames = ('Hertz', 'Galilei', 'Hertz')\n",
116 | "first_names = ('Heinrich', 'Galileo', 'Gustav')\n",
117 | "print np.lexsort((first_names, surnames))"
118 | ]
119 | },
120 | {
121 | "cell_type": "markdown",
122 | "metadata": {},
123 | "source": [
124 | "Q3. Get the indices that would sort x along the second axis."
125 | ]
126 | },
127 | {
128 | "cell_type": "code",
129 | "execution_count": 17,
130 | "metadata": {
131 | "collapsed": false
132 | },
133 | "outputs": [
134 | {
135 | "name": "stdout",
136 | "output_type": "stream",
137 | "text": [
138 | "[[0 1]\n",
139 | " [1 0]]\n"
140 | ]
141 | }
142 | ],
143 | "source": [
144 | "x = np.array([[1,4],[3,1]])\n",
145 | "out = np.argsort(x, axis=1)\n",
146 | "print out"
147 | ]
148 | },
149 | {
150 | "cell_type": "markdown",
151 | "metadata": {},
152 | "source": [
153 | "Q4. Create an array such that its fifth element would be the same as the element of sorted x, and it divide other elements by their value."
154 | ]
155 | },
156 | {
157 | "cell_type": "code",
158 | "execution_count": 48,
159 | "metadata": {
160 | "collapsed": false
161 | },
162 | "outputs": [
163 | {
164 | "name": "stdout",
165 | "output_type": "stream",
166 | "text": [
167 | "x = [5 1 6 3 9 8 2 7 4 0]\n",
168 | "\n",
169 | "Check the fifth element of this new array is 5, the first four elements are all smaller than 5, and 6th through the end are bigger than 5\n",
170 | "[2 0 4 3 1 5 8 7 6 9]\n"
171 | ]
172 | }
173 | ],
174 | "source": [
175 | "x = np.random.permutation(10)\n",
176 | "print \"x =\", x\n",
177 | "print \"\\nCheck the fifth element of this new array is 5, the first four elements are all smaller than 5, and 6th through the end are bigger than 5\\n\", \n",
178 | "out = np.partition(x, 5)\n",
179 | "x.partition(5) # in-place equivalent\n",
180 | "assert np.array_equal(x, out)\n",
181 | "print out\n"
182 | ]
183 | },
184 | {
185 | "cell_type": "markdown",
186 | "metadata": {},
187 | "source": [
188 | "Q5. Create the indices of an array such that its third element would be the same as the element of sorted x, and it divide other elements by their value."
189 | ]
190 | },
191 | {
192 | "cell_type": "code",
193 | "execution_count": 56,
194 | "metadata": {
195 | "collapsed": false
196 | },
197 | "outputs": [
198 | {
199 | "name": "stdout",
200 | "output_type": "stream",
201 | "text": [
202 | "x = [2 8 3 7 5 6 4 0 9 1]\n",
203 | "partitioned = [0 1 2 3 4 5 8 6 9 7]\n",
204 | "indices = [0 1 2 3 4 5 8 6 9 7]\n"
205 | ]
206 | }
207 | ],
208 | "source": [
209 | "x = np.random.permutation(10)\n",
210 | "print \"x =\", x\n",
211 | "partitioned = np.partition(x, 3)\n",
212 | "indices = np.argpartition(x, 3)\n",
213 | "print \"partitioned =\", partitioned\n",
214 | "print \"indices =\", partitioned\n",
215 | "assert np.array_equiv(x[indices], partitioned)"
216 | ]
217 | },
218 | {
219 | "cell_type": "markdown",
220 | "metadata": {},
221 | "source": [
222 | "## Searching"
223 | ]
224 | },
225 | {
226 | "cell_type": "markdown",
227 | "metadata": {},
228 | "source": [
229 | "Q6. Get the maximum and minimum values and their indices of x along the second axis."
230 | ]
231 | },
232 | {
233 | "cell_type": "code",
234 | "execution_count": 78,
235 | "metadata": {
236 | "collapsed": false
237 | },
238 | "outputs": [
239 | {
240 | "name": "stdout",
241 | "output_type": "stream",
242 | "text": [
243 | "x = [[0 5 9 8 2]\n",
244 | " [3 7 4 1 6]]\n",
245 | "maximum values = [9 7]\n",
246 | "max indices = [2 1]\n",
247 | "minimum values = [0 1]\n",
248 | "min indices = [0 3]\n"
249 | ]
250 | }
251 | ],
252 | "source": [
253 | "x = np.random.permutation(10).reshape(2, 5)\n",
254 | "print \"x =\", x\n",
255 | "print \"maximum values =\", np.max(x, 1)\n",
256 | "print \"max indices =\", np.argmax(x, 1)\n",
257 | "print \"minimum values =\", np.min(x, 1)\n",
258 | "print \"min indices =\", np.argmin(x, 1)\n"
259 | ]
260 | },
261 | {
262 | "cell_type": "markdown",
263 | "metadata": {},
264 | "source": [
265 | "Q7. Get the maximum and minimum values and their indices of x along the second axis, ignoring NaNs."
266 | ]
267 | },
268 | {
269 | "cell_type": "code",
270 | "execution_count": 79,
271 | "metadata": {
272 | "collapsed": false
273 | },
274 | "outputs": [
275 | {
276 | "name": "stdout",
277 | "output_type": "stream",
278 | "text": [
279 | "maximum values ignoring NaNs = [ 4. 3.]\n",
280 | "max indices = [1 0]\n",
281 | "minimum values ignoring NaNs = [ 4. 2.]\n",
282 | "min indices = [1 1]\n"
283 | ]
284 | }
285 | ],
286 | "source": [
287 | "x = np.array([[np.nan, 4], [3, 2]])\n",
288 | "print \"maximum values ignoring NaNs =\", np.nanmax(x, 1)\n",
289 | "print \"max indices =\", np.nanargmax(x, 1)\n",
290 | "print \"minimum values ignoring NaNs =\", np.nanmin(x, 1)\n",
291 | "print \"min indices =\", np.nanargmin(x, 1)"
292 | ]
293 | },
294 | {
295 | "cell_type": "markdown",
296 | "metadata": {},
297 | "source": [
298 | "Q8. Get the values and indices of the elements that are bigger than 2 in x.\n"
299 | ]
300 | },
301 | {
302 | "cell_type": "code",
303 | "execution_count": 113,
304 | "metadata": {
305 | "collapsed": false
306 | },
307 | "outputs": [
308 | {
309 | "name": "stdout",
310 | "output_type": "stream",
311 | "text": [
312 | "Values bigger than 2 = [3 3 5]\n",
313 | "Their indices are (array([0, 1, 1], dtype=int64), array([2, 1, 2], dtype=int64))\n"
314 | ]
315 | }
316 | ],
317 | "source": [
318 | "x = np.array([[1, 2, 3], [1, 3, 5]])\n",
319 | "print \"Values bigger than 2 =\", x[x>2]\n",
320 | "print \"Their indices are \", np.nonzero(x > 2)\n",
321 | "assert np.array_equiv(x[x>2], x[np.nonzero(x > 2)])\n",
322 | "assert np.array_equiv(x[x>2], np.extract(x > 2, x))"
323 | ]
324 | },
325 | {
326 | "cell_type": "markdown",
327 | "metadata": {},
328 | "source": [
329 | "Q9. Get the indices of the elements that are bigger than 2 in the flattend x."
330 | ]
331 | },
332 | {
333 | "cell_type": "code",
334 | "execution_count": 100,
335 | "metadata": {
336 | "collapsed": false
337 | },
338 | "outputs": [
339 | {
340 | "name": "stdout",
341 | "output_type": "stream",
342 | "text": [
343 | "[0 1 2 3 4 5]\n"
344 | ]
345 | }
346 | ],
347 | "source": [
348 | "x = np.array([[1, 2, 3], [1, 3, 5]])\n",
349 | "print np.flatnonzero(x)\n",
350 | "assert np.array_equiv(np.flatnonzero(x), x.ravel().nonzero())"
351 | ]
352 | },
353 | {
354 | "cell_type": "markdown",
355 | "metadata": {},
356 | "source": [
357 | "Q10. Check the elements of x and return 0 if it is less than 0, otherwise the element itself."
358 | ]
359 | },
360 | {
361 | "cell_type": "code",
362 | "execution_count": 105,
363 | "metadata": {
364 | "collapsed": false
365 | },
366 | "outputs": [
367 | {
368 | "name": "stdout",
369 | "output_type": "stream",
370 | "text": [
371 | "[[0 0 0]\n",
372 | " [0 0 0]\n",
373 | " [1 2 3]]\n"
374 | ]
375 | }
376 | ],
377 | "source": [
378 | "x = np.arange(-5, 4).reshape(3, 3)\n",
379 | "print np.where(x <0, 0, x)"
380 | ]
381 | },
382 | {
383 | "cell_type": "markdown",
384 | "metadata": {},
385 | "source": [
386 | "Q11. Get the indices where elements of y should be inserted to x to maintain order."
387 | ]
388 | },
389 | {
390 | "cell_type": "code",
391 | "execution_count": 109,
392 | "metadata": {
393 | "collapsed": false
394 | },
395 | "outputs": [
396 | {
397 | "data": {
398 | "text/plain": [
399 | "array([0, 2, 1, 3], dtype=int64)"
400 | ]
401 | },
402 | "execution_count": 109,
403 | "metadata": {},
404 | "output_type": "execute_result"
405 | }
406 | ],
407 | "source": [
408 | "x = [1, 3, 5, 7, 9]\n",
409 | "y = [0, 4, 2, 6]\n",
410 | "np.searchsorted(x, y)"
411 | ]
412 | },
413 | {
414 | "cell_type": "markdown",
415 | "metadata": {},
416 | "source": [
417 | "## Counting"
418 | ]
419 | },
420 | {
421 | "cell_type": "markdown",
422 | "metadata": {},
423 | "source": [
424 | "Q12. Get the number of nonzero elements in x."
425 | ]
426 | },
427 | {
428 | "cell_type": "code",
429 | "execution_count": 120,
430 | "metadata": {
431 | "collapsed": false
432 | },
433 | "outputs": [
434 | {
435 | "name": "stdout",
436 | "output_type": "stream",
437 | "text": [
438 | "5\n"
439 | ]
440 | }
441 | ],
442 | "source": [
443 | "x = [[0,1,7,0,0],[3,0,0,2,19]]\n",
444 | "print np.count_nonzero(x)\n",
445 | "assert np.count_nonzero(x) == len(x[x!=0])"
446 | ]
447 | },
448 | {
449 | "cell_type": "code",
450 | "execution_count": null,
451 | "metadata": {
452 | "collapsed": true
453 | },
454 | "outputs": [],
455 | "source": []
456 | }
457 | ],
458 | "metadata": {
459 | "kernelspec": {
460 | "display_name": "Python 2",
461 | "language": "python",
462 | "name": "python2"
463 | },
464 | "language_info": {
465 | "codemirror_mode": {
466 | "name": "ipython",
467 | "version": 2
468 | },
469 | "file_extension": ".py",
470 | "mimetype": "text/x-python",
471 | "name": "python",
472 | "nbconvert_exporter": "python",
473 | "pygments_lexer": "ipython2",
474 | "version": "2.7.10"
475 | }
476 | },
477 | "nbformat": 4,
478 | "nbformat_minor": 0
479 | }
480 |
--------------------------------------------------------------------------------
/3-rnns/data/names/Japanese.txt:
--------------------------------------------------------------------------------
1 | Abe
2 | Abukara
3 | Adachi
4 | Aida
5 | Aihara
6 | Aizawa
7 | Ajibana
8 | Akaike
9 | Akamatsu
10 | Akatsuka
11 | Akechi
12 | Akera
13 | Akimoto
14 | Akita
15 | Akiyama
16 | Akutagawa
17 | Amagawa
18 | Amaya
19 | Amori
20 | Anami
21 | Ando
22 | Anzai
23 | Aoki
24 | Arai
25 | Arakawa
26 | Araki
27 | Arakida
28 | Arato
29 | Arihyoshi
30 | Arishima
31 | Arita
32 | Ariwa
33 | Ariwara
34 | Asahara
35 | Asahi
36 | Asai
37 | Asano
38 | Asanuma
39 | Asari
40 | Ashia
41 | Ashida
42 | Ashikaga
43 | Asuhara
44 | Atshushi
45 | Ayabito
46 | Ayugai
47 | Baba
48 | Baisotei
49 | Bando
50 | Bunya
51 | Chiba
52 | Chikamatsu
53 | Chikanatsu
54 | Chino
55 | Chishu
56 | Choshi
57 | Daishi
58 | Dan
59 | Date
60 | Dazai
61 | Deguchi
62 | Deushi
63 | Doi
64 | Ebina
65 | Ebisawa
66 | Eda
67 | Egami
68 | Eguchi
69 | Ekiguchi
70 | Endo
71 | Endoso
72 | Enoki
73 | Enomoto
74 | Erizawa
75 | Eto
76 | Etsuko
77 | Ezakiya
78 | Fuchida
79 | Fugunaga
80 | Fujikage
81 | Fujimaki
82 | Fujimoto
83 | Fujioka
84 | Fujishima
85 | Fujita
86 | Fujiwara
87 | Fukao
88 | Fukayama
89 | Fukuda
90 | Fukumitsu
91 | Fukunaka
92 | Fukuoka
93 | Fukusaku
94 | Fukushima
95 | Fukuyama
96 | Fukuzawa
97 | Fumihiko
98 | Funabashi
99 | Funaki
100 | Funakoshi
101 | Furusawa
102 | Fuschida
103 | Fuse
104 | Futabatei
105 | Fuwa
106 | Gakusha
107 | Genda
108 | Genji
109 | Gensai
110 | Godo
111 | Goto
112 | Gushiken
113 | Hachirobei
114 | Haga
115 | Hagino
116 | Hagiwara
117 | Hama
118 | Hamacho
119 | Hamada
120 | Hamaguchi
121 | Hamamoto
122 | Hanabusa
123 | Hanari
124 | Handa
125 | Hara
126 | Harada
127 | Haruguchi
128 | Hasegawa
129 | Hasekura
130 | Hashimoto
131 | Hasimoto
132 | Hatakeda
133 | Hatakeyama
134 | Hatayama
135 | Hatoyama
136 | Hattori
137 | Hayakawa
138 | Hayami
139 | Hayashi
140 | Hayashida
141 | Hayata
142 | Hayuata
143 | Hida
144 | Hideaki
145 | Hideki
146 | Hideyoshi
147 | Higashikuni
148 | Higashiyama
149 | Higo
150 | Higoshi
151 | Higuchi
152 | Hike
153 | Hino
154 | Hira
155 | Hiraga
156 | Hiraki
157 | Hirano
158 | Hiranuma
159 | Hiraoka
160 | Hirase
161 | Hirasi
162 | Hirata
163 | Hiratasuka
164 | Hirayama
165 | Hiro
166 | Hirose
167 | Hirota
168 | Hiroyuki
169 | Hisamatsu
170 | Hishida
171 | Hishikawa
172 | Hitomi
173 | Hiyama
174 | Hohki
175 | Hojo
176 | Hokusai
177 | Honami
178 | Honda
179 | Hori
180 | Horigome
181 | Horigoshi
182 | Horiuchi
183 | Horri
184 | Hoshino
185 | Hosokawa
186 | Hosokaya
187 | Hotate
188 | Hotta
189 | Hyata
190 | Hyobanshi
191 | Ibi
192 | Ibu
193 | Ibuka
194 | Ichigawa
195 | Ichihara
196 | Ichikawa
197 | Ichimonji
198 | Ichiro
199 | Ichisada
200 | Ichiyusai
201 | Idane
202 | Iemochi
203 | Ienari
204 | Iesada
205 | Ieyasu
206 | Ieyoshi
207 | Igarashi
208 | Ihara
209 | Ii
210 | Iida
211 | Iijima
212 | Iitaka
213 | Ijichi
214 | Ijiri
215 | Ikeda
216 | Ikina
217 | Ikoma
218 | Imada
219 | Imagawa
220 | Imai
221 | Imaizumi
222 | Imamura
223 | Imoo
224 | Ina
225 | Inaba
226 | Inao
227 | Inihara
228 | Ino
229 | Inoguchi
230 | Inokuma
231 | Inoue
232 | Inouye
233 | Inukai
234 | Ippitsusai
235 | Irie
236 | Iriye
237 | Isayama
238 | Ise
239 | Iseki
240 | Iseya
241 | Ishibashi
242 | Ishida
243 | Ishiguro
244 | Ishihara
245 | Ishikawa
246 | Ishimaru
247 | Ishimura
248 | Ishinomori
249 | Ishiyama
250 | Isobe
251 | Isoda
252 | Isozaki
253 | Itagaki
254 | Itami
255 | Ito
256 | Itoh
257 | Iwahara
258 | Iwahashi
259 | Iwakura
260 | Iwasa
261 | Iwasaki
262 | Izumi
263 | Jimbo
264 | Jippensha
265 | Jo
266 | Joshuya
267 | Joshuyo
268 | Jukodo
269 | Jumonji
270 | Kada
271 | Kagabu
272 | Kagawa
273 | Kahae
274 | Kahaya
275 | Kaibara
276 | Kaima
277 | Kajahara
278 | Kajitani
279 | Kajiwara
280 | Kajiyama
281 | Kakinomoto
282 | Kakutama
283 | Kamachi
284 | Kamata
285 | Kaminaga
286 | Kamio
287 | Kamioka
288 | Kamisaka
289 | Kamo
290 | Kamon
291 | Kan
292 | Kanada
293 | Kanagaki
294 | Kanegawa
295 | Kaneko
296 | Kanesaka
297 | Kano
298 | Karamorita
299 | Karube
300 | Karubo
301 | Kasahara
302 | Kasai
303 | Kasamatsu
304 | Kasaya
305 | Kase
306 | Kashiwagi
307 | Kasuse
308 | Kataoka
309 | Katayama
310 | Katayanagi
311 | Kate
312 | Kato
313 | Katoaka
314 | Katsu
315 | Katsukawa
316 | Katsumata
317 | Katsura
318 | Katsushika
319 | Kawabata
320 | Kawachi
321 | Kawagichi
322 | Kawagishi
323 | Kawaguchi
324 | Kawai
325 | Kawaii
326 | Kawakami
327 | Kawamata
328 | Kawamura
329 | Kawasaki
330 | Kawasawa
331 | Kawashima
332 | Kawasie
333 | Kawatake
334 | Kawate
335 | Kawayama
336 | Kawazu
337 | Kaza
338 | Kazuyoshi
339 | Kenkyusha
340 | Kenmotsu
341 | Kentaro
342 | Ki
343 | Kido
344 | Kihara
345 | Kijimuta
346 | Kijmuta
347 | Kikkawa
348 | Kikuchi
349 | Kikugawa
350 | Kikui
351 | Kikutake
352 | Kimio
353 | Kimiyama
354 | Kimura
355 | Kinashita
356 | Kinoshita
357 | Kinugasa
358 | Kira
359 | Kishi
360 | Kiski
361 | Kita
362 | Kitabatake
363 | Kitagawa
364 | Kitamura
365 | Kitano
366 | Kitao
367 | Kitoaji
368 | Ko
369 | Kobayashi
370 | Kobi
371 | Kodama
372 | Koga
373 | Kogara
374 | Kogo
375 | Koguchi
376 | Koiso
377 | Koizumi
378 | Kojima
379 | Kokan
380 | Komagata
381 | Komatsu
382 | Komatsuzaki
383 | Komine
384 | Komiya
385 | Komon
386 | Komura
387 | Kon
388 | Konae
389 | Konda
390 | Kondo
391 | Konishi
392 | Kono
393 | Konoe
394 | Koruba
395 | Koshin
396 | Kotara
397 | Kotoku
398 | Koyama
399 | Koyanagi
400 | Kozu
401 | Kubo
402 | Kubota
403 | Kudara
404 | Kudo
405 | Kuga
406 | Kumagae
407 | Kumasaka
408 | Kunda
409 | Kunikida
410 | Kunisada
411 | Kuno
412 | Kunomasu
413 | Kuramochi
414 | Kuramoto
415 | Kurata
416 | Kurkawa
417 | Kurmochi
418 | Kuroda
419 | Kurofuji
420 | Kurogane
421 | Kurohiko
422 | Kuroki
423 | Kurosawa
424 | Kurusu
425 | Kusatsu
426 | Kusonoki
427 | Kusuhara
428 | Kusunoki
429 | Kuwabara
430 | Kwakami
431 | Kyubei
432 | Maeda
433 | Maehata
434 | Maeno
435 | Maita
436 | Makiguchi
437 | Makino
438 | Makioka
439 | Makuda
440 | Marubeni
441 | Marugo
442 | Marusa
443 | Maruya
444 | Maruyama
445 | Masanobu
446 | Masaoka
447 | Mashita
448 | Masoni
449 | Masudu
450 | Masuko
451 | Masuno
452 | Masuzoe
453 | Matano
454 | Matokai
455 | Matoke
456 | Matsuda
457 | Matsukata
458 | Matsuki
459 | Matsumara
460 | Matsumoto
461 | Matsumura
462 | Matsuo
463 | Matsuoka
464 | Matsura
465 | Matsushina
466 | Matsushita
467 | Matsuya
468 | Matsuzawa
469 | Mayuzumi
470 | Mazaki
471 | Mazawa
472 | Mazuka
473 | Mifune
474 | Mihashi
475 | Miki
476 | Mimasuya
477 | Minabuchi
478 | Minami
479 | Minamoto
480 | Minatoya
481 | Minobe
482 | Mishima
483 | Mitsubishi
484 | Mitsuharu
485 | Mitsui
486 | Mitsukuri
487 | Mitsuwa
488 | Mitsuya
489 | Mitzusaka
490 | Miura
491 | Miwa
492 | Miyagi
493 | Miyahara
494 | Miyajima
495 | Miyake
496 | Miyamae
497 | Miyamoto
498 | Miyazaki
499 | Miyazawa
500 | Miyoshi
501 | Mizoguchi
502 | Mizumaki
503 | Mizuno
504 | Mizutani
505 | Modegi
506 | Momotami
507 | Momotani
508 | Monomonoi
509 | Mori
510 | Moriguchi
511 | Morimoto
512 | Morinaga
513 | Morioka
514 | Morishita
515 | Morisue
516 | Morita
517 | Morri
518 | Moto
519 | Motoori
520 | Motoyoshi
521 | Munakata
522 | Munkata
523 | Muraguchi
524 | Murakami
525 | Muraoka
526 | Murasaki
527 | Murase
528 | Murata
529 | Murkami
530 | Muro
531 | Muruyama
532 | Mushanaokoji
533 | Mushashibo
534 | Muso
535 | Mutsu
536 | Nagahama
537 | Nagai
538 | Nagano
539 | Nagasawa
540 | Nagase
541 | Nagata
542 | Nagatsuka
543 | Nagumo
544 | Naito
545 | Nakada
546 | Nakadai
547 | Nakadan
548 | Nakae
549 | Nakagawa
550 | Nakahara
551 | Nakajima
552 | Nakamoto
553 | Nakamura
554 | Nakane
555 | Nakanishi
556 | Nakano
557 | Nakanoi
558 | Nakao
559 | Nakasato
560 | Nakasawa
561 | Nakasone
562 | Nakata
563 | Nakatoni
564 | Nakayama
565 | Nakazawa
566 | Namiki
567 | Nanami
568 | Narahashi
569 | Narato
570 | Narita
571 | Nataga
572 | Natsume
573 | Nawabe
574 | Nemoto
575 | Niijima
576 | Nijo
577 | Ninomiya
578 | Nishi
579 | Nishihara
580 | Nishikawa
581 | Nishimoto
582 | Nishimura
583 | Nishimuraya
584 | Nishio
585 | Nishiwaki
586 | Nitta
587 | Nobunaga
588 | Noda
589 | Nogi
590 | Noguchi
591 | Nogushi
592 | Nomura
593 | Nonomura
594 | Noro
595 | Nosaka
596 | Nose
597 | Nozaki
598 | Nozara
599 | Numajiri
600 | Numata
601 | Obata
602 | Obinata
603 | Obuchi
604 | Ochiai
605 | Ochida
606 | Odaka
607 | Ogata
608 | Ogiwara
609 | Ogura
610 | Ogyu
611 | Ohba
612 | Ohira
613 | Ohishi
614 | Ohka
615 | Ohmae
616 | Ohmiya
617 | Oichi
618 | Oinuma
619 | Oishi
620 | Okabe
621 | Okada
622 | Okakura
623 | Okamoto
624 | Okamura
625 | Okanao
626 | Okanaya
627 | Okano
628 | Okasawa
629 | Okawa
630 | Okazaki
631 | Okazawaya
632 | Okimasa
633 | Okimoto
634 | Okita
635 | Okubo
636 | Okuda
637 | Okui
638 | Okuma
639 | Okuma
640 | Okumura
641 | Okura
642 | Omori
643 | Omura
644 | Onishi
645 | Ono
646 | Onoda
647 | Onoe
648 | Onohara
649 | Ooka
650 | Osagawa
651 | Osaragi
652 | Oshima
653 | Oshin
654 | Ota
655 | Otaka
656 | Otake
657 | Otani
658 | Otomo
659 | Otsu
660 | Otsuka
661 | Ouchi
662 | Oyama
663 | Ozaki
664 | Ozawa
665 | Ozu
666 | Raikatuji
667 | Royama
668 | Ryusaki
669 | Sada
670 | Saeki
671 | Saga
672 | Saigo
673 | Saiki
674 | Saionji
675 | Saito
676 | Saitoh
677 | Saji
678 | Sakagami
679 | Sakai
680 | Sakakibara
681 | Sakamoto
682 | Sakanoue
683 | Sakata
684 | Sakiyurai
685 | Sakoda
686 | Sakubara
687 | Sakuraba
688 | Sakurai
689 | Sammiya
690 | Sanda
691 | Sanjo
692 | Sano
693 | Santo
694 | Saromi
695 | Sarumara
696 | Sasada
697 | Sasakawa
698 | Sasaki
699 | Sassa
700 | Satake
701 | Sato
702 | Satoh
703 | Satoya
704 | Sawamatsu
705 | Sawamura
706 | Sayuki
707 | Segawa
708 | Sekigawa
709 | Sekine
710 | Sekozawa
711 | Sen
712 | Senmatsu
713 | Seo
714 | Serizawa
715 | Shiba
716 | Shibaguchi
717 | Shibanuma
718 | Shibasaki
719 | Shibasawa
720 | Shibata
721 | Shibukji
722 | Shichirobei
723 | Shidehara
724 | Shiga
725 | Shiganori
726 | Shige
727 | Shigeki
728 | Shigemitsu
729 | Shigi
730 | Shikitei
731 | Shikuk
732 | Shima
733 | Shimada
734 | Shimakage
735 | Shimamura
736 | Shimanouchi
737 | Shimaoka
738 | Shimazaki
739 | Shimazu
740 | Shimedzu
741 | Shimizu
742 | Shimohira
743 | Shimon
744 | Shimura
745 | Shimuzu
746 | Shinko
747 | Shinozaki
748 | Shinozuka
749 | Shintaro
750 | Shiokawa
751 | Shiomi
752 | Shiomiya
753 | Shionoya
754 | Shiotani
755 | Shioya
756 | Shirahata
757 | Shirai
758 | Shiraishi
759 | Shirane
760 | Shirasu
761 | Shiratori
762 | Shirokawa
763 | Shiroyama
764 | Shiskikura
765 | Shizuma
766 | Shobo
767 | Shoda
768 | Shunji
769 | Shunsen
770 | Siagyo
771 | Soga
772 | Sohda
773 | Soho
774 | Soma
775 | Someya
776 | Sone
777 | Sonoda
778 | Soseki
779 | Sotomura
780 | Suenami
781 | Sugai
782 | Sugase
783 | Sugawara
784 | Sugihara
785 | Sugimura
786 | Sugisata
787 | Sugita
788 | Sugitani
789 | Sugiyama
790 | Sumitimo
791 | Sunada
792 | Suzambo
793 | Suzuki
794 | Tabuchi
795 | Tadeshi
796 | Tagawa
797 | Taguchi
798 | Taira
799 | Taka
800 | Takabe
801 | Takagaki
802 | Takagawa
803 | Takagi
804 | Takahama
805 | Takahashi
806 | Takaki
807 | Takamura
808 | Takano
809 | Takaoka
810 | Takara
811 | Takarabe
812 | Takashi
813 | Takashita
814 | Takasu
815 | Takasugi
816 | Takayama
817 | Takecare
818 | Takeda
819 | Takei
820 | Takekawa
821 | Takemago
822 | Takemitsu
823 | Takemura
824 | Takenouchi
825 | Takeshita
826 | Taketomo
827 | Takeuchi
828 | Takewaki
829 | Takimoto
830 | Takishida
831 | Takishita
832 | Takizawa
833 | Taku
834 | Takudo
835 | Takudome
836 | Tamazaki
837 | Tamura
838 | Tamuro
839 | Tanaka
840 | Tange
841 | Tani
842 | Taniguchi
843 | Tanizaki
844 | Tankoshitsu
845 | Tansho
846 | Tanuma
847 | Tarumi
848 | Tatenaka
849 | Tatsuko
850 | Tatsuno
851 | Tatsuya
852 | Tawaraya
853 | Tayama
854 | Temko
855 | Tenshin
856 | Terada
857 | Terajima
858 | Terakado
859 | Terauchi
860 | Teshigahara
861 | Teshima
862 | Tochikura
863 | Togo
864 | Tojo
865 | Tokaji
866 | Tokuda
867 | Tokudome
868 | Tokuoka
869 | Tomika
870 | Tomimoto
871 | Tomioka
872 | Tommii
873 | Tomonaga
874 | Tomori
875 | Tono
876 | Torii
877 | Torisei
878 | Toru
879 | Toshishai
880 | Toshitala
881 | Toshusai
882 | Toyama
883 | Toyoda
884 | Toyoshima
885 | Toyota
886 | Toyotomi
887 | Tsubouchi
888 | Tsucgimoto
889 | Tsuchie
890 | Tsuda
891 | Tsuji
892 | Tsujimoto
893 | Tsujimura
894 | Tsukada
895 | Tsukade
896 | Tsukahara
897 | Tsukamoto
898 | Tsukatani
899 | Tsukawaki
900 | Tsukehara
901 | Tsukioka
902 | Tsumemasa
903 | Tsumura
904 | Tsunoda
905 | Tsurimi
906 | Tsuruga
907 | Tsuruya
908 | Tsushima
909 | Tsutaya
910 | Tsutomu
911 | Uboshita
912 | Uchida
913 | Uchiyama
914 | Ueda
915 | Uehara
916 | Uemura
917 | Ueshima
918 | Uesugi
919 | Uetake
920 | Ugaki
921 | Ui
922 | Ukiyo
923 | Umari
924 | Umehara
925 | Umeki
926 | Uno
927 | Uoya
928 | Urogataya
929 | Usami
930 | Ushiba
931 | Utagawa
932 | Wakai
933 | Wakatsuki
934 | Watabe
935 | Watanabe
936 | Watari
937 | Watnabe
938 | Watoga
939 | Yakuta
940 | Yamabe
941 | Yamada
942 | Yamagata
943 | Yamaguchi
944 | Yamaguchiya
945 | Yamaha
946 | Yamahata
947 | Yamakage
948 | Yamakawa
949 | Yamakazi
950 | Yamamoto
951 | Yamamura
952 | Yamana
953 | Yamanaka
954 | Yamanouchi
955 | Yamanoue
956 | Yamaoka
957 | Yamashita
958 | Yamato
959 | Yamawaki
960 | Yamazaki
961 | Yamhata
962 | Yamura
963 | Yanagawa
964 | Yanagi
965 | Yanagimoto
966 | Yanagita
967 | Yano
968 | Yasuda
969 | Yasuhiro
970 | Yasui
971 | Yasujiro
972 | Yasukawa
973 | Yasutake
974 | Yoemon
975 | Yokokawa
976 | Yokoyama
977 | Yonai
978 | Yosano
979 | Yoshida
980 | Yoshifumi
981 | Yoshihara
982 | Yoshikawa
983 | Yoshimatsu
984 | Yoshinobu
985 | Yoshioka
986 | Yoshitomi
987 | Yoshizaki
988 | Yoshizawa
989 | Yuasa
990 | Yuhara
991 | Yunokawa
992 |
--------------------------------------------------------------------------------
/0-libraries/numpy-exercises/05-input-and-output.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Input and Output"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 2,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": [
16 | "import numpy as np"
17 | ]
18 | },
19 | {
20 | "cell_type": "code",
21 | "execution_count": 3,
22 | "metadata": {},
23 | "outputs": [
24 | {
25 | "data": {
26 | "text/plain": [
27 | "'1.13.3'"
28 | ]
29 | },
30 | "execution_count": 3,
31 | "metadata": {},
32 | "output_type": "execute_result"
33 | }
34 | ],
35 | "source": [
36 | "np.__version__"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": 4,
42 | "metadata": {},
43 | "outputs": [
44 | {
45 | "name": "stdout",
46 | "output_type": "stream",
47 | "text": [
48 | "2017-10-02\n"
49 | ]
50 | }
51 | ],
52 | "source": [
53 | "from datetime import date\n",
54 | "print(date.today())"
55 | ]
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "metadata": {},
60 | "source": [
61 | "## NumPy binary files (NPY, NPZ)"
62 | ]
63 | },
64 | {
65 | "cell_type": "markdown",
66 | "metadata": {},
67 | "source": [
68 | "Q1. Save x into `temp.npy` and load it."
69 | ]
70 | },
71 | {
72 | "cell_type": "code",
73 | "execution_count": 10,
74 | "metadata": {},
75 | "outputs": [
76 | {
77 | "name": "stdout",
78 | "output_type": "stream",
79 | "text": [
80 | "True\n"
81 | ]
82 | }
83 | ],
84 | "source": [
85 | "x = np.arange(10)\n",
86 | "np.save(\"temp.npy\", x)\n",
87 | "\n",
88 | "# Check if there exists the 'temp.npy' file.\n",
89 | "import os\n",
90 | "if os.path.exists('temp.npy'):\n",
91 | " x2 = np.load(\"temp.npy\")\n",
92 | " print(np.array_equal(x, x2))\n"
93 | ]
94 | },
95 | {
96 | "cell_type": "markdown",
97 | "metadata": {},
98 | "source": [
99 | "Q2. Save x and y into a single file 'temp.npz' and load it."
100 | ]
101 | },
102 | {
103 | "cell_type": "code",
104 | "execution_count": 18,
105 | "metadata": {},
106 | "outputs": [
107 | {
108 | "name": "stdout",
109 | "output_type": "stream",
110 | "text": [
111 | "True\n",
112 | "True\n"
113 | ]
114 | }
115 | ],
116 | "source": [
117 | "x = np.arange(10)\n",
118 | "y = np.arange(11, 20)\n",
119 | "np.savez(\"temp.npz\", x=x, y=y)\n",
120 | "\n",
121 | "with np.load(\"temp.npz\") as data:\n",
122 | " x2 = data['x']\n",
123 | " y2 = data['y']\n",
124 | " print(np.array_equal(x, x2))\n",
125 | " print(np.array_equal(y, y2))\n",
126 | "??np.savez"
127 | ]
128 | },
129 | {
130 | "cell_type": "markdown",
131 | "metadata": {},
132 | "source": [
133 | "## Text files"
134 | ]
135 | },
136 | {
137 | "cell_type": "markdown",
138 | "metadata": {},
139 | "source": [
140 | "Q3. Save x to 'temp.txt' in string format and load it."
141 | ]
142 | },
143 | {
144 | "cell_type": "code",
145 | "execution_count": 41,
146 | "metadata": {},
147 | "outputs": [
148 | {
149 | "data": {
150 | "text/plain": [
151 | "array([['0', '1', '2', '3', '4'],\n",
152 | " ['5', '6', '7', '8', '9']],\n",
153 | " dtype='\n",
98 | "_X, _Y, _Z, ...: NumPy 2-d or higer dimensional arrays
\n",
99 | "x, y, z, ...: 0-d or 1-d tensors
\n",
100 | "X, Y, Z, ...: 2-d or higher dimensional tensors"
101 | ]
102 | },
103 | {
104 | "cell_type": "markdown",
105 | "metadata": {},
106 | "source": [
107 | "## Order statistics"
108 | ]
109 | },
110 | {
111 | "cell_type": "markdown",
112 | "metadata": {},
113 | "source": [
114 | "Q0. Return the maximum value and its location of all elements along the second axis in X."
115 | ]
116 | },
117 | {
118 | "cell_type": "code",
119 | "execution_count": 3,
120 | "metadata": {},
121 | "outputs": [
122 | {
123 | "name": "stdout",
124 | "output_type": "stream",
125 | "text": [
126 | "• maximum values= \n",
127 | " 4\n",
128 | " 8\n",
129 | "[torch.FloatTensor of size 2]\n",
130 | "\n",
131 | "• the first indices= \n",
132 | " 3\n",
133 | " 1\n",
134 | "[torch.LongTensor of size 2]\n",
135 | "\n"
136 | ]
137 | }
138 | ],
139 | "source": [
140 | "X = torch.Tensor(\n",
141 | " [[1, 2, 2, 4, 4],\n",
142 | " [5, 8, 7, 8, 5]])\n",
143 | "\n",
144 | "maxs, indices = ...\n",
145 | "print(\"• maximum values=\", maxs)\n",
146 | "print(\"• the first indices=\", indices)"
147 | ]
148 | },
149 | {
150 | "cell_type": "markdown",
151 | "metadata": {},
152 | "source": [
153 | "Q1. Return the minimum value and its location of all elements along the first axis in X, retaining the dimension."
154 | ]
155 | },
156 | {
157 | "cell_type": "code",
158 | "execution_count": 4,
159 | "metadata": {},
160 | "outputs": [
161 | {
162 | "name": "stdout",
163 | "output_type": "stream",
164 | "text": [
165 | "• minimum values= \n",
166 | " 1 2 2 4 4\n",
167 | "[torch.FloatTensor of size 1x5]\n",
168 | "\n",
169 | "• the first indices= \n",
170 | " 0 0 0 0 0\n",
171 | "[torch.LongTensor of size 1x5]\n",
172 | "\n"
173 | ]
174 | }
175 | ],
176 | "source": [
177 | "X = torch.Tensor(\n",
178 | " [[1, 2, 2, 4, 4],\n",
179 | " [5, 8, 7, 8, 5]])\n",
180 | "\n",
181 | "mins, indices = ...\n",
182 | "print(\"• minimum values=\", mins)\n",
183 | "print(\"• the first indices=\", indices)"
184 | ]
185 | },
186 | {
187 | "cell_type": "markdown",
188 | "metadata": {},
189 | "source": [
190 | "Q2. Return the 3 largest elements and their indices along the second dimension."
191 | ]
192 | },
193 | {
194 | "cell_type": "code",
195 | "execution_count": 5,
196 | "metadata": {},
197 | "outputs": [
198 | {
199 | "name": "stdout",
200 | "output_type": "stream",
201 | "text": [
202 | "• the 3 largest values= \n",
203 | " 4 4 2\n",
204 | " 8 8 7\n",
205 | "[torch.FloatTensor of size 2x3]\n",
206 | "\n",
207 | "• the first indices= \n",
208 | " 3 4 1\n",
209 | " 1 3 2\n",
210 | "[torch.LongTensor of size 2x3]\n",
211 | "\n"
212 | ]
213 | }
214 | ],
215 | "source": [
216 | "X = torch.Tensor(\n",
217 | " [[1, 2, 2, 4, 4],\n",
218 | " [5, 8, 7, 8, 5]])\n",
219 | "\n",
220 | "top3, indices = ...\n",
221 | "print(\"• the 3 largest values=\", top3)\n",
222 | "print(\"• the first indices=\", indices)"
223 | ]
224 | },
225 | {
226 | "cell_type": "markdown",
227 | "metadata": {},
228 | "source": [
229 | "Q3. Return the 3 smallest elements and their indices along the second dimension."
230 | ]
231 | },
232 | {
233 | "cell_type": "code",
234 | "execution_count": 6,
235 | "metadata": {},
236 | "outputs": [
237 | {
238 | "name": "stdout",
239 | "output_type": "stream",
240 | "text": [
241 | "• the 3 smallest values= \n",
242 | " 1 2 2\n",
243 | " 5 5 7\n",
244 | "[torch.FloatTensor of size 2x3]\n",
245 | "\n",
246 | "• the first indices= \n",
247 | " 0 2 1\n",
248 | " 4 0 2\n",
249 | "[torch.LongTensor of size 2x3]\n",
250 | "\n"
251 | ]
252 | }
253 | ],
254 | "source": [
255 | "X = torch.Tensor(\n",
256 | " [[1, 2, 2, 4, 4],\n",
257 | " [5, 8, 7, 8, 5]])\n",
258 | "\n",
259 | "bottom3, indices = ...\n",
260 | "print(\"• the 3 smallest values=\", bottom3)\n",
261 | "print(\"• the first indices=\", indices)"
262 | ]
263 | },
264 | {
265 | "cell_type": "markdown",
266 | "metadata": {},
267 | "source": [
268 | "Q4. Return the 3rd smallest elements of X along the second dimension."
269 | ]
270 | },
271 | {
272 | "cell_type": "code",
273 | "execution_count": 7,
274 | "metadata": {},
275 | "outputs": [
276 | {
277 | "name": "stdout",
278 | "output_type": "stream",
279 | "text": [
280 | "• X= \n",
281 | " 1 2 2 4 5 6 7 8 9 10\n",
282 | " 11 12 13 14 11 11 17 18 19 20\n",
283 | "[torch.FloatTensor of size 2x10]\n",
284 | "\n",
285 | "• the 3rd smallest elements= \n",
286 | " 2\n",
287 | " 11\n",
288 | "[torch.FloatTensor of size 2]\n",
289 | "\n",
290 | "• indices= \n",
291 | " 2\n",
292 | " 0\n",
293 | "[torch.LongTensor of size 2]\n",
294 | "\n"
295 | ]
296 | }
297 | ],
298 | "source": [
299 | "X = torch.arange(1, 21).resize_(2, 10)\n",
300 | "X[0, 2:3]=2\n",
301 | "X[1, 4:6]=11\n",
302 | "print(\"• X=\", X)\n",
303 | "\n",
304 | "values, indices = ...\n",
305 | "print(\"• the 3rd smallest elements=\", values)\n",
306 | "print(\"• indices=\", indices)"
307 | ]
308 | },
309 | {
310 | "cell_type": "markdown",
311 | "metadata": {},
312 | "source": [
313 | "## Averages and variances"
314 | ]
315 | },
316 | {
317 | "cell_type": "markdown",
318 | "metadata": {},
319 | "source": [
320 | "Q5. Compute the mean of X along the second axis."
321 | ]
322 | },
323 | {
324 | "cell_type": "code",
325 | "execution_count": 8,
326 | "metadata": {},
327 | "outputs": [
328 | {
329 | "name": "stdout",
330 | "output_type": "stream",
331 | "text": [
332 | "• X= \n",
333 | " 1 2 3 4 5 6 7 8 9 10\n",
334 | " 11 12 13 14 15 16 17 18 19 20\n",
335 | "[torch.FloatTensor of size 2x10]\n",
336 | "\n",
337 | "• mean= \n",
338 | " 5.5000\n",
339 | " 15.5000\n",
340 | "[torch.FloatTensor of size 2]\n",
341 | "\n"
342 | ]
343 | }
344 | ],
345 | "source": [
346 | "X = torch.arange(1, 21).resize_(2, 10)\n",
347 | "print(\"• X=\", X)\n",
348 | "mean = ...\n",
349 | "print(\"• mean=\", mean)\n"
350 | ]
351 | },
352 | {
353 | "cell_type": "markdown",
354 | "metadata": {},
355 | "source": [
356 | "Q6. Compute the median of x."
357 | ]
358 | },
359 | {
360 | "cell_type": "code",
361 | "execution_count": 9,
362 | "metadata": {},
363 | "outputs": [
364 | {
365 | "name": "stdout",
366 | "output_type": "stream",
367 | "text": [
368 | "• x= \n",
369 | " 0\n",
370 | " 1\n",
371 | " 2\n",
372 | " 3\n",
373 | " 4\n",
374 | " 5\n",
375 | " 6\n",
376 | " 7\n",
377 | " 8\n",
378 | " 9\n",
379 | "[torch.FloatTensor of size 10]\n",
380 | "\n",
381 | "• median= 4.0\n"
382 | ]
383 | }
384 | ],
385 | "source": [
386 | "x = torch.arange(0,10)\n",
387 | "print(\"• x=\", x)\n",
388 | "median = ...\n",
389 | "print(\"• median=\", median)"
390 | ]
391 | },
392 | {
393 | "cell_type": "markdown",
394 | "metadata": {},
395 | "source": [
396 | "Q7. Compute the median and its index of X along the second axis."
397 | ]
398 | },
399 | {
400 | "cell_type": "code",
401 | "execution_count": 10,
402 | "metadata": {},
403 | "outputs": [
404 | {
405 | "name": "stdout",
406 | "output_type": "stream",
407 | "text": [
408 | "• X= \n",
409 | " 1 2 3 4 5 6 7 8 9 10\n",
410 | " 11 12 13 14 15 16 17 18 19 20\n",
411 | "[torch.FloatTensor of size 2x10]\n",
412 | "\n",
413 | "• medians= \n",
414 | " 5\n",
415 | " 15\n",
416 | "[torch.FloatTensor of size 2]\n",
417 | "\n",
418 | "• indices= \n",
419 | " 4\n",
420 | " 4\n",
421 | "[torch.LongTensor of size 2]\n",
422 | "\n"
423 | ]
424 | }
425 | ],
426 | "source": [
427 | "X = torch.arange(1, 21).resize_(2, 10)\n",
428 | "print(\"• X=\", X)\n",
429 | "medians, indices = ...\n",
430 | "print(\"• medians=\", medians)\n",
431 | "print(\"• indices=\", indices)\n"
432 | ]
433 | },
434 | {
435 | "cell_type": "markdown",
436 | "metadata": {},
437 | "source": [
438 | "Q8. Compute the mode and its index of X along the second axis."
439 | ]
440 | },
441 | {
442 | "cell_type": "code",
443 | "execution_count": 11,
444 | "metadata": {},
445 | "outputs": [
446 | {
447 | "name": "stdout",
448 | "output_type": "stream",
449 | "text": [
450 | "• modes= \n",
451 | " 0\n",
452 | " 1\n",
453 | "[torch.FloatTensor of size 2]\n",
454 | "\n",
455 | "• the last indices= \n",
456 | " 3\n",
457 | " 4\n",
458 | "[torch.LongTensor of size 2]\n",
459 | "\n"
460 | ]
461 | }
462 | ],
463 | "source": [
464 | "X = torch.Tensor([[1,1,0,0,3],\n",
465 | " [3,4,1,1,1]])\n",
466 | "\n",
467 | "modes, indices = ...\n",
468 | "print(\"• modes=\", modes)\n",
469 | "print(\"• the last indices=\", indices)\n"
470 | ]
471 | },
472 | {
473 | "cell_type": "markdown",
474 | "metadata": {},
475 | "source": [
476 | "Q9. Compute the variance of X along the second axis without Bessel's correction."
477 | ]
478 | },
479 | {
480 | "cell_type": "code",
481 | "execution_count": 22,
482 | "metadata": {},
483 | "outputs": [
484 | {
485 | "name": "stdout",
486 | "output_type": "stream",
487 | "text": [
488 | "• X= \n",
489 | " 1 2 3 4 5 6 7 8 9 10\n",
490 | " 11 12 13 14 15 16 17 18 19 20\n",
491 | "[torch.FloatTensor of size 2x10]\n",
492 | "\n",
493 | "• variances= \n",
494 | " 8.2500\n",
495 | " 8.2500\n",
496 | "[torch.FloatTensor of size 2]\n",
497 | "\n"
498 | ]
499 | }
500 | ],
501 | "source": [
502 | "X = torch.arange(1, 21).resize_(2, 10)\n",
503 | "print(\"• X=\", X)\n",
504 | "variances = ...\n",
505 | "print(\"• variances=\", variances)\n"
506 | ]
507 | },
508 | {
509 | "cell_type": "markdown",
510 | "metadata": {},
511 | "source": [
512 | "Q10. Compute the std of X along the second axis with Bessel's correction."
513 | ]
514 | },
515 | {
516 | "cell_type": "code",
517 | "execution_count": 24,
518 | "metadata": {},
519 | "outputs": [
520 | {
521 | "name": "stdout",
522 | "output_type": "stream",
523 | "text": [
524 | "• X= \n",
525 | " 1 2 3 4 5 6 7 8 9 10\n",
526 | " 11 12 13 14 15 16 17 18 19 20\n",
527 | "[torch.FloatTensor of size 2x10]\n",
528 | "\n",
529 | "• standard deviations= \n",
530 | " 3.0277\n",
531 | " 3.0276\n",
532 | "[torch.FloatTensor of size 2]\n",
533 | "\n"
534 | ]
535 | }
536 | ],
537 | "source": [
538 | "X = torch.arange(1, 21).resize_(2, 10)\n",
539 | "print(\"• X=\", X)\n",
540 | "stds = ...\n",
541 | "print(\"• standard deviations=\", stds)"
542 | ]
543 | },
544 | {
545 | "cell_type": "code",
546 | "execution_count": null,
547 | "metadata": {
548 | "collapsed": true
549 | },
550 | "outputs": [],
551 | "source": []
552 | }
553 | ],
554 | "metadata": {
555 | "anaconda-cloud": {},
556 | "kernelspec": {
557 | "display_name": "Python 2",
558 | "language": "python",
559 | "name": "python2"
560 | },
561 | "language_info": {
562 | "codemirror_mode": {
563 | "name": "ipython",
564 | "version": 2
565 | },
566 | "file_extension": ".py",
567 | "mimetype": "text/x-python",
568 | "name": "python",
569 | "nbconvert_exporter": "python",
570 | "pygments_lexer": "ipython2",
571 | "version": "2.7.12"
572 | }
573 | },
574 | "nbformat": 4,
575 | "nbformat_minor": 1
576 | }
577 |
--------------------------------------------------------------------------------