The following for you to share a Python3 library NumPy array properties of the viewing method, with a good reference value, I hope to help you. Come and see it together.
The examples are as follows:
Import NumPy as NPA1 = Np.array ([1,2,3,4],dtype=np.complex128) print (A1) print ("Data type", type (A1)) #打印数组数据类型print (" Array element data type: ", A1.dtype) #打印数组元素数据类型print (" Total number of elements of the array: ", a1.size) #打印数组尺寸, that is, the total number of array elements print (" array shape: ", A1.shape) # Prints the array shape print ("Number of dimensions of the array", A1.ndim) #打印数组的维度数目
However, it is more convenient to construct a function that can display array properties at once
Import NumPy as Npdef arrayinfo (A1): "" "one-time rendering of an array of many information" "" a2 = Np.array ([up]) #创建一个参照物数组 if type (a1)! = Type (A2): #判断传入参数是否为数组类型 Print ("It's Not a Numpy.ndarray") return None print (A1) Print ("Data type" , type (A1)) #打印数组数据类型 print ("array element data type:", A1.dtype) #打印数组元素数据类型 Print ("Total number of array elements:", a1.size) # Prints the array size, that is, the total number of array elements print ("Array shape:", A1.shape) #打印数组形状 Print ("Number of dimensions of the array", A1.ndim) # Number of dimensions of the printed array arrayinfo (A1)