numpy 数组对象

numpy 数组对象
NumPy中的ndarray是一个多维数组对象,该对象由两部分组成:实际的数据,描述这些数据的元数据
# eg_v1

import numpy as np
a = np.arange(5) # 创建一个包含5个元素的NumPy数组a,取值分别为0~4的整数
print (a)
# [0 1 2 3 4]
print (a.dtype) # dtype 查看数组的数据类型
# int32 (数组a的数据类型为int32)

# 确定数组的维度(数组的shape属性返回一个元组(tuple),元组中的元素即为NumPy数组每一个维度上的大小)

a1 = a.shape
print (a1)
# (5,) # 包含5个元素的数组

# shape (查看数组的纬度)

a2 = a.shape
print (a2)
# (5,)
b = np.array([[1,2,3,4],[5,6,7,8]])
print (b.shape)
# (2, 4)


# 数组元素

c = np.array([[1,2],[3,4]])
print (c)
#[[1 2]
# [3 4]]
c0 = c[0,0]
print (c0)
# 1
c1 = c[0,1]
print (c1)
# 2
c2 = c[1,0]
print (c2)
# 3
c3 = c[1,1]
print (c3)
# 4

转载于:https://www.cnblogs.com/xieshengsen/p/6619017.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值