刘刚刚的个人博客

02-numpy数组对象的基本属性

创建时间:2020-12-19 22:22:04
更新时间:2020-12-19 22:22:20

array数组是numpy最核心的数据结构

array对象的属性

array的属性主要包括:shape、ndim、size、dtype

# 先创建好初始数据
import numpy as np
x = np.array([1,2,3,4,5,6,7,8])
y = np.array([
    [1,2,3,4,5,6,7,8],
    [1,2,3,4,5,6,7,8]
])

image-20201217234244586

  • shape:获取array的形状,即行数和列数

    x.shape
    y.shape

    image-20201217234644425

  • ndim:获取array的维度数量

    x.ndim
    y.ndim

    image-20201217235024843

  • size:获取array的元素数量

    x.size
    y.size

    image-20201217235131452

  • dtype:获取array的数据类型

    x.dtype
    y.dtype

    image-20201217235240007

我的名片

昵称:shuta

职业:后台开发(python、php)

邮箱:648949076@qq.com

站点信息

建站时间: 2020/2/19
网站程序: ANTD PRO VUE + TP6.0
晋ICP备18007778号