1. Linear algebra
Matrix multiplication dot function
x= Np.array ([[[1,2,3],[4,5,6]]) y=np.array ([[[6,23],[-1,7],[8,9]]) xout[]: Array ([[1, 2, 3], [4, 5, 6]]) yout[6, [1], [-7 ] ; 8, 9 ] ]) X.dot (y) out[ (67, 181])
A two-dimensional array followed by the matrix dot product operation of a well-sized one-dimensional array will be given a one-dimensional array.
Np.dot (X,np.ones (3)) out[]: Array ([ 6., 15.])
Numpy.linalg
fromNumpy.linalgImportInv,qrx= Np.random.randn (5,5) Mat=X.t.dot (x) Inv (MAT) out[24]: Array ([[183.76974989,-623.36361091,-583.49826184,-235.16948917, -181.68152874], [ -623.36361091, 2121.59301898, 1985.26883645, 799.39704159, 619.72162247], [ -583.49826184, 1985.26883645, 1858.87861876, 747.67011221, 578.69498867], [ -235.16948917, 799.39704159, 747.67011221, 301.90295918, 233.89701649], [ -181.68152874, 619.72162247, 578.69498867, 233.89701649, 182.77441114])
2. Random number generation
The Numpy.random module complements Python's built-in function random.
For example, the normal function can generate a sample array of 4*4:
Samples = np.random.normal (size = (bis)) samplesout[]: Array ([[-1.22102285, 2.08688133, 1.15874399, 0.14342708], [-0.29772372, 0.36137871, 0.60243437, -0.09287792], [-0.49263459, 0.69445334, 1.02035894, -1.18263174], [-0.07184985,- 1.11834445, 0.89547984, 0.0585053]])
3. Example
Random Walk 1000:
nsteps = np.random.randint (0,2,size= Np.where (draws>0,1,-1= steps.cumsum () Walk.min ()
Simulate more than one random stroll at a time.
Nwalk ==1000=5000= np.random.randint (0,2,size == np.where (Draws > 0, 1,-1 = steps.cumsum (1) walksout[]: Array ([[[ 1], 2, 1, ..., +, 15, +], -1, 0, -1, ..., (+ ), [0 ], 1, -36,., -35, -36, ..., -1, 0, 1, ..., -16, -17, -18], [ 1, 0, 1, ..., a , 10 ], -1, 0, -1, ..., -8, -9, -8]], Dtype=int32)
-04-numpy Foundation for data analysis using Python