python中numpy数组的常见属性

1.ndim属性:
表示数组的是几维的(一维数组或者二维数组等)

2.shape属性:
表示数组的形状(3*3数组,或者其他)

3.size属性:
包含的元素的个数

4.dtype属性:
元素的类型
注意:不能直接通过修改数组的dtype属性,得到一个新的数组,如果需要转换数组元素的数据类型,需要使用astype方法
array_test = np.array([1.5,2,3,4,5,6])
array_test2= array_test.astype(‘int32’)

5.itemsize属性:
元素所占的字节数

猜你喜欢

转载自blog.csdn.net/qq_35833972/article/details/89436933
今日推荐