当前位置 博文首页 > 小旺的博客: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)
结果: