In [1]:
import numpy as np
import matplotlib.pyplot as pp

In [2]:
%matplotlib inline

In [3]:
x = np.linspace(0,10,40)

In [4]:
x


Out[4]:
array([  0.        ,   0.25641026,   0.51282051,   0.76923077,
         1.02564103,   1.28205128,   1.53846154,   1.79487179,
         2.05128205,   2.30769231,   2.56410256,   2.82051282,
         3.07692308,   3.33333333,   3.58974359,   3.84615385,
         4.1025641 ,   4.35897436,   4.61538462,   4.87179487,
         5.12820513,   5.38461538,   5.64102564,   5.8974359 ,
         6.15384615,   6.41025641,   6.66666667,   6.92307692,
         7.17948718,   7.43589744,   7.69230769,   7.94871795,
         8.20512821,   8.46153846,   8.71794872,   8.97435897,
         9.23076923,   9.48717949,   9.74358974,  10.        ])

In [6]:
sinx = np.sin(x)

In [7]:
pp.plot(x,sinx)


Out[7]:
[<matplotlib.lines.Line2D at 0x108c2f160>]

In [8]:
cosx = np.cos(x)

In [9]:
pp.plot(x,sinx)
pp.plot(x,cosx)

pp.legend(['sin(x)','cos(x)'])


Out[9]:
<matplotlib.legend.Legend at 0x108d1ef28>

In [10]:
y = sinx * cosx
z = cosx**2 - sinx**2

pp.plot(x,y)
pp.plot(x,z)


Out[10]:
[<matplotlib.lines.Line2D at 0x108c91860>]

In [11]:
np.dot(sinx,cosx)


Out[11]:
0.79265269738691613

In [12]:
np.outer(sinx,cosx)


Out[12]:
array([[ 0.        ,  0.        ,  0.        , ..., -0.        ,
        -0.        , -0.        ],
       [ 0.25360981,  0.24531844,  0.22098649, ..., -0.2531162 ,
        -0.24083004, -0.21279677],
       [ 0.49063689,  0.4745963 ,  0.42752338, ..., -0.48968194,
        -0.46591297, -0.41167944],
       ..., 
       [-0.06236104, -0.06032224, -0.05433917, ...,  0.06223966,
         0.05921857,  0.05232537],
       [-0.31343844, -0.30319107, -0.27311901, ...,  0.31282838,
         0.29764381,  0.26299727],
       [-0.54402111, -0.52623521, -0.47404048, ...,  0.54296226,
         0.51660708,  0.45647263]])

In [13]:
v = np.linspace(0,10,5)
v + 1


Out[13]:
array([  1. ,   3.5,   6. ,   8.5,  11. ])

In [14]:
vv = np.outer(v,v)
vv + v


Out[14]:
array([[   0.  ,    2.5 ,    5.  ,    7.5 ,   10.  ],
       [   0.  ,    8.75,   17.5 ,   26.25,   35.  ],
       [   0.  ,   15.  ,   30.  ,   45.  ,   60.  ],
       [   0.  ,   21.25,   42.5 ,   63.75,   85.  ],
       [   0.  ,   27.5 ,   55.  ,   82.5 ,  110.  ]])

In [15]:
vv + v[:,np.newaxis]


Out[15]:
array([[   0.  ,    0.  ,    0.  ,    0.  ,    0.  ],
       [   2.5 ,    8.75,   15.  ,   21.25,   27.5 ],
       [   5.  ,   17.5 ,   30.  ,   42.5 ,   55.  ],
       [   7.5 ,   26.25,   45.  ,   63.75,   82.5 ],
       [  10.  ,   35.  ,   60.  ,   85.  ,  110.  ]])

In [ ]: