Python3 Library NumPy How to view array properties

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.