In [1]:
import numpy
print numpy.__version__

import matplotlib.pyplot as plt
%matplotlib inline

x = [1, 2, 3, 4, 5, 6]
np_arr = numpy.array(x)

# output
x


1.9.0
Out[1]:
[1, 2, 3, 4, 5, 6]

In [2]:
np_arr


Out[2]:
array([1, 2, 3, 4, 5, 6])

In [3]:
np_arr.shape


Out[3]:
(6,)

In [4]:
x == np_arr


Out[4]:
array([ True,  True,  True,  True,  True,  True], dtype=bool)

In [5]:
x = [ [1,2], [3,4], [5,6]]
np_arr = numpy.array(x)
np_arr.shape


Out[5]:
(3, 2)

In [6]:
array_slice = np_arr[:,1]
array_slice


Out[6]:
array([2, 4, 6])

In [7]:
array_slice[2] = 7
np_arr * 3
np_arr.T.dot(np_arr)


Out[7]:
array([[35, 49],
       [49, 69]])

In [8]:
numpy.average(np_arr) + 1


Out[8]:
4.6666666666666661

In [9]:
numpy.average(np_arr[:,1])


Out[9]:
4.333333333333333

In [10]:
np_arr
numpy.cov(np_arr)


Out[10]:
array([[ 0.5,  0.5,  1. ],
       [ 0.5,  0.5,  1. ],
       [ 1. ,  1. ,  2. ]])

In [2]:
x = [ 0, 1, 2, 3, 4, 5, 6 ]
y = [ 0, 2, 4, 8, 16, 32, 64 ]
plt.plot(x, y)


Out[2]:
[<matplotlib.lines.Line2D at 0x105a5d850>]

In [12]:
plt.plot(x, y, 'g--', label='my line')
plt.legend()


Out[12]:
<matplotlib.legend.Legend at 0x108176a90>

In [13]:
plt.plot(x, y, 'b*')
plt.axis(xmin=-10, xmax=8, ymin=-10)


Out[13]:
(-10, 8, -10, 70.0)

In [14]:
x = numpy.linspace(0, 25, 100)
y = x ** 2

In [15]:
plt.plot(x,y, 'r*')


Out[15]:
[<matplotlib.lines.Line2D at 0x10b27e6d0>]

In [16]:
import sklearn.datasets as datasets
plt.jet()
X, Y = datasets.make_blobs(centers=4, cluster_std=0.5, random_state=0)
plt.scatter(X[:,0], X[:,1], c=Y)


Out[16]:
<matplotlib.collections.PathCollection at 0x10c233750>

In [ ]: