NumPy
1.如何创建一个numpy.array?
# 创建
np.array(3, dtype=int) # 创建一个数组
np.arange(10, 2, -2) # 按序创建一个数组
np.full(shape=(3, 5), fill_value=666) # 创建一个3行5列,元素为666的矩阵
np.empty(3, dtype=int) # 创建一个伪随机数组,实际是空
np.ones(3, dtype=int) # 创建一个全是1的数组
np.zeros(3, dtype=int) # 创建一个全是0的数组
np.eye(3, 5, dtype=int) # 创建一个i=j全为1的
np.diag([3, 4, 5], 1) # 从下标为1处开始
np.vander([1, 2, 3], 4) # 生成每一列都是输入一维数组或列表或元组的递减幂, x其中最高多项式阶数为n-1
np.concatenate((a, b), axis=0) # 将两个数组拼接
np.linspace(a, b, 3) # 线性分割 在[a, b]中等长截取n个点,包括a和b
np.logspace(2, 3, 3) # 以10为底,划分 10的平方~10的立方,平均划分
np.random.randint(a, b) # [a, b)间的整数
np.random.randint(a, b, size=10) # 从[a, b)中有放回的选取10个整数
np.random.random((a, b)) # 创建a行b列的矩阵,元素随机
np.random.seed(66) # 随机种子:使随机产生的数固定
np.indices((3, 4)) # 生成两个规定行列相同的数组,分别按行和列从0开始
np.fromstring(d, dtype=np.int8) # 将字符串以ASCII码形式输出
2.numpy.array的属性
# 形状
a.shape # 形状
a.ndim # 维度
a.size # 元素个数
np.reshape(-