In [0]:
import numpy
In [1]:
import scipy
In [2]:
import matplotlib
In [3]:
import sklearn
In [4]:
import psutil
In [5]:
import pandas
In [6]:
import IPython.parallel
Finding the location of an installed package and its version:
In [7]:
numpy.__path__
Out[7]:
In [8]:
numpy.__version__
Out[8]:
In [9]:
%run ../fetch_data.py
In [10]:
import os
for fname in os.listdir('../datasets/'):
print(fname)
In [11]:
import numpy as np
In [12]:
a = np.array([1, 2, 3])
In [13]:
a
Out[13]:
In [14]:
b = np.array([[0, 2, 4], [1, 3, 5]])
In [15]:
b
Out[15]:
In [16]:
b.shape
Out[16]:
In [17]:
b.dtype
Out[17]:
In [18]:
a.shape
Out[18]:
In [19]:
a.dtype
Out[19]:
In [20]:
np.zeros(5)
Out[20]:
In [21]:
np.ones(shape=(3, 4), dtype=np.int32)
Out[21]:
In [22]:
c = b * 0.5
In [23]:
c
Out[23]:
In [24]:
c.shape
Out[24]:
In [25]:
c.dtype
Out[25]:
In [26]:
a
Out[26]:
In [27]:
d = a + c
In [28]:
d
Out[28]:
In [29]:
d[0]
Out[29]:
In [30]:
d[0, 0]
Out[30]:
In [31]:
d[:, 0]
Out[31]:
In [32]:
d.sum()
Out[32]:
In [33]:
d.mean()
Out[33]:
In [34]:
d.sum(axis=0)
Out[34]:
In [35]:
d.mean(axis=1)
Out[35]:
In [36]:
e = np.arange(12)
In [37]:
e
Out[37]:
In [38]:
f = e.reshape(3, 4)
In [39]:
f
Out[39]:
In [40]:
e
Out[40]:
In [41]:
e[5:] = 0
In [42]:
e
Out[42]:
In [43]:
f
Out[43]:
In [44]:
a
Out[44]:
In [45]:
b
Out[45]:
In [46]:
d
Out[46]:
In [47]:
np.concatenate([a, a, a])
Out[47]:
In [48]:
np.vstack([a, b, d])
Out[48]:
In [49]:
np.hstack([b, d])
Out[49]:
In [50]:
%matplotlib inline
In [51]:
import matplotlib.pyplot as plt
In [52]:
x = np.linspace(0, 2, 10)
In [53]:
x
Out[53]:
In [54]:
plt.plot(x, 'o-');
In [55]:
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');
In [56]:
samples = np.random.normal(loc=1.0, scale=0.5, size=1000)
In [57]:
samples.shape
Out[57]:
In [58]:
samples.dtype
Out[58]:
In [59]:
samples[:30]
Out[59]:
In [60]:
plt.hist(samples, bins=50);
In [61]:
samples_1 = np.random.normal(loc=1, scale=.5, size=10000)
samples_2 = np.random.standard_t(df=10, size=10000)
In [62]:
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');
In [63]:
plt.scatter(samples_1, samples_2, alpha=0.1);
In [64]: