1 ImportNumPy as NP2 #Base Properties3Array = Np.array ([[[+], [0,0,1]], [[+], [0,0,1]]],4Dtype =Np.int64)5 6 Print(Array)7 Print(Array.ndim)#Number of Dim8 Print(Array.shape)#Shape9 Print(array.size)#Number of elementsTen Print(Array.dtype) One A #Create an array -A = Np.array ([1,2,3,4])#1 Dim - theb = Np.array ([[1,2,3,4]])#row vector, 2 Dim -c = Np.array ([[1], [2], [3], [4]])#column vector, 2 Dim - Print(A.shape, B.shape, C.shape) - +A = Np.zeros ((2,3), Dtype =np.float) -A = Np.ones ((2,3), Dtype =np.float) +A = Np.empty ((2,3), Dtype =np.float) AA = Np.arange (10, 20)#alike function range atA = Np.linspace (1, 10, 5)#interval - Print(a) - - #base operation (vector operation) - " "Vector" " -A = Np.array ([10, 20, 30, 40]) inb = Np.arange (4) - Print(A +b) to Print(a**2) + Print(A < 20) - the " "Matrix" " *A = Np.array ([[], $[0,1]])Panax Notoginsengb = Np.arange (4). Reshape (2,2)) - Print(A *b) the Print(Np.dot (A, B))#equal A.dot (b) + A Print(Np.argmax (a)) the Print(Np.argmin (a)) + -A = Np.arange (2,-1). Reshape (3,4)) $ Print(Np.clip (A, 5, 9)) $ - " "Random number" " #Module:np.random -A = Np.random.random ((2,4)) the Print(a) - Print(Np.sum (A, Axis = 1))Wuyi Print(Np.min (A, Axis =0)) the - #Index Wu " "one-dimensional array" " -A = Np.arange (3, 15) About Print(a[2]) $ Print(A[0:5:2]) - - " "two-dimensional array" " -A = Np.arange (3, +). Reshape (3, 4) A Print(a[2]) + Print(a[2,:]) the - Print(a[2][1]) $ Print(A[2, 1]) the the #array Merge theA = Np.array ([1,1,1]) theB = Np.array ([2,2,2]) - in Print(Np.vstack ((b)))#Vertival Stack the Print(Np.hstack ((b)))#Horizontal Stack the AboutA[np.newaxis,:]#1 * 3 thea[:, Np.newaxis]#3 * 1 the theA = Np.array ([[1, 2], [3, 4]]) +b = Np.array ([[5, 6]]) - the #Array SegmentationBayiA = Np.arange (A). Reshape (3,4)) the the Print(Np.split (A, 2, Axis = 1)) - Print(Np.array_split (A, 3, Axis = 1)) - Print(Np.split (A, 3, Axis =0)) the the Print(Np.vsplit (A, 3)) the Print(Np.hsplit (A, 2)) the - #copy and deep copy theA = Np.array ([1,2,3,10]) theb =a thec =a94D =b the theb =a.copy () theA[3] = 4498 Print(a) About Print(b)
Python:numpy Learning