import numpy as np
arr = np.array([1, 2, 3])
print(arr.shape)
print(arr)
arr = np.arange(10)
print(arr.shape)
print(arr)
# (开始,截止,步长)
# [开始,截止)范围内步长为间隔的更新
arr = np.arange(0, 10, 2.5)
print(arr.shape)
print(arr)
# 在一个区间内返回等间距数组
arr = np.linspace(0, 100, 5)
print(arr.shape)
print(arr)
# 不包括右区间的值
arr = np.linspace(0, 100, 5, endpoint=False)
print(arr.shape)
print(arr)
# 将列表转化为矩阵
mat = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
print(mat.shape)
print(mat)
# 默认:数轴越靠前,变化越快
mat = mat.reshape(3, 3)
print(mat.shape)
print(mat)
# 增加第三个维度
mat = mat.reshape(1, 3, 3)
print(mat.shape)
print(mat)
# 矩阵初始化
# 两行两列,均为0
mat = np.zeros((2, 2))
print(mat.shape)
print(mat)
# 两行三列,均为1
mat = np.ones((2, 3))
print(mat.shape)
print(mat)
mat = np.full((2, 2), -np.inf) # np.inf是∞
print(mat.shape)
print(mat)
mat = np.full((2, 2), [1, 2])
print(mat.shape)
print(mat)
print(np.e)
print(np.inf)
print(np.pi)
# 数组/向量之间的运算
vec1 = np.array([1, 2, 3])
vec2 = np.array([1, 2, 3])
print(vec1 + vec2)
print(vec1 - vec2)
print(vec1 * vec2)
print(vec1 / vec2)
# 矩阵的内积
print(np.dot(vec1, vec2))
# 矩阵的外积
print(np.outer(vec1, vec2))
mat = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]).reshape(3, 3)
print(mat) # 矩阵形状
print(mat.shape) # 几行几列
print(mat.dtype) # 数据类型
标签:arr,mat,python,学习,np,shape,vec2,print,numpy From: https://www.cnblogs.com/mendianyu/p/17300021.html