In [1]:
pip install numpy
Requirement already satisfied: numpy in c:\users\dengzl\.conda\envs\data_analysis\lib\site-packages (1.26.0) Note: you may need to restart the kernel to use updated packages.In [2]:
# 创建一个一维数组 import numpy as np d1 = np.array([1,2,3,4,5]) d1Out[2]:
array([1, 2, 3, 4, 5])In [3]:
# 属性: size数据大小 d1.sizeOut[3]:
5In [7]:
# 属性:type数据类型 type(d1)Out[7]:
numpy.ndarrayIn [8]:
# ndim数据维度 d1.ndimOut[8]:
1In [11]:
# 创建二位数组 d2 = np.arange(15) d2Out[11]:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])In [14]:
# 增加行、列维度 d2 = d2.reshape(3,5) d2Out[14]:
array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14]])In [15]:
# 打印属性 d2.sizeOut[15]:
15In [16]:
d2.ndimOut[16]:
2In [17]:
type(d2)Out[17]:
numpy.ndarrayIn [ ]: 标签:11,d2,基础,array,Out,numpy,d1 From: https://www.cnblogs.com/mlzxdzl/p/17767793.html