Python-NumPy模块-查看数组属性

查看数组的行数和列数

from numpy import array
a=array([[1,1],[2,2],[3,3]])
print(a.shape)

结果:


在这里插入图片描述

提取数组的行数或列数

from numpy import array
a=array([[1,1],[2,2],[3,3]])
print(a.shape)
print(a.shape[0])
print(a.shape[1])

结果:


在这里插入图片描述

查看数组的元素个数

from numpy import array
a=array([[1,1],[2,2],[3,3]])
print(a.size)

结果:


在这里插入图片描述

查看和转换数组元素的数据类型

from numpy import array
a=array([[1,1],[2,2],[3,3]])
b=array([[1.5,1],[2,2],[3,3]])
print(a.dtype)
print(b.dtype)

结果:


在这里插入图片描述

astype()函数进行数据类型转换

from numpy import array
a=array([[1,1],[2,2],[3,3]])
b=array([[1.5,1],[2,2],[3,3]])
b=b.astype(int)
print(a.dtype)
print(b.dtype)

结果:


在这里插入图片描述

查看数组的维数

from numpy import array
a=array([[1,1],[2,2],[3,3]])
b=array([1.5,1,2,2])
print(a.ndim)
print(b.ndim)

结果:


在这里插入图片描述
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容