The following code is a few basic uses of numpy, including arrays and matrix operations ...
1 ImportNumPy as NP2 Print "<== print version ==>"3 Printnp.version.version4 Print "<== 1-dimensional Array ==>"5 PrintNp.array ([1, 2, 3, 4, 5])6 Print "<== 2-dimentional Array ==>"7 PrintNp.array ([[1,2],[3,4]])8 Print "<== int32,int16,etc. ==>"9 PrintNp.array ((1, 2, 3, 4), Dtype =Np.float64)Ten Print "<== get a 3*5 array ==>" One PrintNp.arange (Reshape) (3, 5) A Print "<== generate 4 data from 1 to 5 ==>" - PrintNp.linspace (1, 5, 4) - Print "<== what's in matlab ==>" the PrintNp.zeros ((2, 5))# - Print '\ n' - PrintNp.ones ((2,5)) - Print '\ n' + PrintNp.eye (3) - +A = Np.eye (4) A Print "<== sum ==>" at a.sum () -A.sum (axis=0) - Print "<== min and Max ==>" - a.min () - A.max () - Np.sin (a) in Np.floor (a) - Np.exp (a) to Np.dot (A, a) + -A = Np.ones ((2,2)) theb = Np.eye (2) * Print "<== visit Array ==>" $ Printa[0, 0]Panax Notoginseng Print "<== Merge:shallow Copy:learn from V and H ==>" - PrintNp.vstack ((b)) the PrintNp.hstack ((b)) + Print "<== deep Copy ==>" Ac =a.copy () the Print "<== Transpose ==>" + Printc.transpose () - Print "<== Trace ==>" $ Printc.trace () $ Print "<== more matrix operations in Linalg ==>" - ImportNumpy.linalg as NPLG - PrintNplg.eig (a)
View Code
Python NumPy Learning Notes (i)