Home > Article > Backend Development > How to view numpy array attributes in python3 library
Below I will share with you an article on how to view the numpy array attributes of the python3 library. It has a good reference value and I hope it will be helpful to everyone. Let’s come and take a look
The example is as follows:
import numpy as np a1 = np.array([1,2,3,4],dtype=np.complex128) print(a1) print("数据类型",type(a1)) #打印数组数据类型 print("数组元素数据类型:",a1.dtype) #打印数组元素数据类型 print("数组元素总数:",a1.size) #打印数组尺寸,即数组元素总数 print("数组形状:",a1.shape) #打印数组形状 print("数组的维度数目",a1.ndim) #打印数组的维度数目
However, it is more convenient to construct a function that can display the array attributes at once
import numpy as np def arrayinfo(a1): """一次性呈现数组的许多信息""" a2 = np.array([1,2]) #创建一个参照物数组 if type(a1) != type(a2): #判断传入参数是否为数组类型 print("It's not an numpy.ndarray") return None print(a1) print("数据类型",type(a1)) #打印数组数据类型 print("数组元素数据类型:",a1.dtype) #打印数组元素数据类型 print("数组元素总数:",a1.size) #打印数组尺寸,即数组元素总数 print("数组形状:",a1.shape) #打印数组形状 print("数组的维度数目",a1.ndim) #打印数组的维度数目 arrayinfo(a1)
Related recommendations:
How about Python Numpy Operating Arrays and Matrices
The above is the detailed content of How to view numpy array attributes in python3 library. For more information, please follow other related articles on the PHP Chinese website!