import numpy as np def asum(a_list,b_list,n1=2,n2=3): a = np.array(a_list) b = np.array(b_list) c = pow(a,n1) + pow(b,n2) return c a_lst = [1,2,3,4] b_lst = [2,3,4,5] print(asum(a_lst,b_lst)) #np.array()生成数据对象ndarray a = np.array([[1,2,3,4],[1,2,3,4]]) print(type(a)) #<class 'numpy.ndarray'> print(a) print(a.ndim)#轴数 print(a.shape) # (2,4) 2 4 rows Print (a.size) # The total number of elements Print (a.itemsize) # element size Print (a.dtype) # Int32, element type Print (np.arange (10 )) Print (np.ones ((3,3), DTYPE = np.float32)) # generates three lines of the matrix 1 are three Print (np.ones ([4,3-], DTYPE = NP. Int32)) # supra four rows and three columns, the type of the parameter list is also OK Print (np.zeros ((2,3))) # two rows and three columns 0 Print (np.full ((3,3),. 6)) # 3 are three rows. 6 print (np.eye (. 6)) # diagonal is a square matrix of rows and 6 columns 1,6 # generated multidimensional array print(np.ones ((2,3,4), DTYPE = np.int32)) # mimic the shape of the green list 0 Chengdu matrix Print (np.zeros_like ([[2,3,4,5], [. 3, 4,5,6 ], [0,0,0,0]])) # mimic the shape of the green list 1 Chengdu matrix Print (np.ones_like ([[2,3,4,5], [3,4- , 5,6 ], [0,0,0,0]])) # mimic the shape of the green list Chengdu matrix 10 Print (np.full_like ([[2,3,4,5], [3,4-, 5,6], [0,0,0,0]], 10 )) # generates four elements 1 starting end 10, is equally divided into three Print (np.linspace (1,10,4 )) # does not contain 10 four elements, it is necessary to cake into four Print (np.linspace (1,10,4, Endpoint = False)) # the two arrays into a = np.linspace (1,10,4 ) B = NP .linspace (1,10,4, endpoint =False) C = np.concatenate ((A, B)) Print (C) # [4. 1. 10. The 1. 7. The 3.25 5.5 7.75] # the RESHAPE A = np.ones ((2,3,4), = DTYPE np.int32) Print (a) C = a.reshape ((3,8)) # does not change the original array Print (C) Print (a) a.resize (( 3,8)) # change the original array a Print (a) # fatten reduced dimensional array a.flatten () Print (a) # no change D = a.flatten () # modified based on the new array Print (D) #asType () array type conversion element group A = np.ones ((2,3,4), DTYPE = np.int) print (A) B = a.astype (np.float) # copy the new data may then change the type of print (B) # data to the list conversion .ToList () A = np.full ((2,3,4), 25, DTYPE = np.int32) Print (A) Print (a.tolist ()) # in the new array based on the change Print (A) # original array unchanged # array slice A = np.array ([1,2,3,4,5,6 ]) Print (A [2 ]) Print (A [. 1:. 4: 2]) # starting number comprising no A = np.arange (24 ) Print (A) a.resize ((3,2,4 )) Print (A) Print (A [2,1, 3]) # outermost row 3, line 2 inside, which fourth element Print (A [-2, -1, -3 ]) Print (A [:,. 1, -3 ]) Print (A [:,. 1: 2 ,:]) Print (A [:,:, :: 2 ]) B = np.arange (48) .reshape (3,4,4 ) Print (B) # average matrix Print (a.mean ()) Print (np.arange (2) .mean ()) # 0.5 # a divided by the average a = a / a .mean () Print (a) # unary functions, square a = np.arange (24) .reshape (2,3,4 ) Print (A) A = np.square (A) Print (A) # square root of A = np.arange (24) .reshape (2,3,4 ) A = np.sqrt (A) Print (A) # integers and fractional partial peeling Print (np.modf (a)) # two matrix, the first matrix is the fractional part, the second matrix is the integer part # binary function instance, two matrices a = np.arange (24). the RESHAPE (2,3,4 ) B = np.sqrt (A) Print (A) Print (B) Print (np.maximum (A, B)) # difference between the two types of data matrices, taken float Print (A > b)