import numpy

import matplotlib

import sklearn

import pandas

"""
Explanation: Tutorial Setup
Check your install
End of explanation
"""


numpy.__path__

numpy.__version__

"""
Explanation: Finding the location of an installed package and its version:
End of explanation
"""


!pip install version_information

%load_ext version_information
%version_information numpy, scipy, matplotlib, pandas, tensorflow, sklearn, skflow

"""
Explanation: Or check it all at once:  pip install version_information and check versions with a magic command.
End of explanation
"""


import numpy as np

a = np.array([1, 2, 3])

a

b = np.array([[0, 2, 4], [1, 3, 5]])

b

b.shape

b.dtype

a.shape

a.dtype

np.zeros(5)

np.ones(shape=(3, 4), dtype=np.int32)

"""
Explanation: A NumPy primer
NumPy array dtypes and shapes
End of explanation
"""


c = b * 0.5

c

c.shape

c.dtype

a

d = a + c

d

d[0]

d[0, 0]

d[:, 0]

d.sum()

d.mean()

d.sum(axis=0)

d.mean(axis=1)

"""
Explanation: Common array operations
End of explanation
"""


e = np.arange(12)

e

f = e.reshape(3, 4)

f

e

e[5:] = 0

e

f

"""
Explanation: Reshaping and inplace update
End of explanation
"""


a

b

d

np.concatenate([a, a, a])

np.vstack([a, b, d])

np.hstack([b, d])

"""
Explanation: Combining arrays
End of explanation
"""


%matplotlib inline

import matplotlib.pyplot as plt

x = np.linspace(0, 2, 10)

x

plt.plot(x, 'o-');

plt.plot(x, x, 'o-', label='linear')
plt.plot(x, x ** 2, 'x-', label='quadratic')

plt.legend(loc='best')
plt.title('Linear vs Quadratic progression')
plt.xlabel('Input')
plt.ylabel('Output');

samples = np.random.normal(loc=1.0, scale=0.5, size=1000)

samples.shape

samples.dtype

samples[:30]

plt.hist(samples, bins=50);

samples_1 = np.random.normal(loc=1, scale=.5, size=10000)
samples_2 = np.random.standard_t(df=10, size=10000)

bins = np.linspace(-3, 3, 50)
_ = plt.hist(samples_1, bins=bins, alpha=0.5, label='samples 1')
_ = plt.hist(samples_2, bins=bins, alpha=0.5, label='samples 2')
plt.legend(loc='upper left');

plt.scatter(samples_1, samples_2, alpha=0.1)

samples_3 = np.random.normal(loc=2, scale=.5, size=10000)

fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.scatter(samples_1, samples_2, alpha=0.1, c='b', marker="s", label='first')
ax1.scatter(samples_3, samples_2, alpha=0.1, c='r', marker="o", label='second')
plt.show()

"""
Explanation: Also see this fun "100 numpy exercises" site
A Matplotlib primer
End of explanation
"""


