Numpy核心功能简易代码

NumPy(Numerical Python)是 Python 科学计算的核心库,专门用于高效处理数值数组。

NumPy核心功能包括:多维数组ndarray、数学运算(add/multiply)、线性代数(dot/inv)、统计函数(mean/std)、随机生成(randn/randint)、广播机制、向量化计算。

代码块如下:

python 复制代码
#创建数组
shuzu1 = np.array([1,2,3,4,5])
print("数组",shuzu1)
print("形状",shuzu1.shape)
#加法和乘法运算
shuzu2 = np.array([1,2,3])
shuzu3 = np.array([4,5,6])
print("加法",shuzu2+shuzu3)
print("乘法",shuzu1*2)
#矩阵运算
matrix = np.array([[1,2],[3,4]])
print("矩阵加法",np.add(matrix,matrix))
print("矩阵乘法",np.dot(matrix,matrix))

#统计运算
data = np.random.randint(100)  #100个随机数
print("均值",np.mean(data))
print("标准差",np.std(data)) 

运行效果图:

相关推荐
TechEdu2026063 天前
[人工智能]Python07:NumPy Selection:详细实践指南
人工智能·numpy
TechEdu2026063 天前
[人工智能]Python09:numpy.random.Statistics统计实战指南
人工智能·numpy
TechEdu2026063 天前
[人工智能]Python10:NumPy.random.Algebra 随机代数实战指南
人工智能·numpy
TechEdu2026065 天前
[人工智能]Python08:NumPy 检查与诊断
人工智能·numpy
TechEdu2026066 天前
[人工智能]Python06:NumPy 数组操作详解
人工智能·numpy
Xiu Yan13 天前
Python 数据分析:Pandas DataFrame 零基础入门教程
python·jupyter·pycharm·numpy·pandas
醇氧13 天前
Git 合并冲突与`__pycache__` 的恩怨情仇
python·numpy·fastapi
Xiu Yan14 天前
Python 数据分析:Pandas Series 零基础入门教程
python·jupyter·pycharm·numpy·pandas
lpfasd12316 天前
配置文件格式对比 与 AI Coding 的选择逻辑
python·flask·numpy
jzshmyt17 天前
我用 Python 从零“生成“了一个宇宙,然后让它观察自己(v14)
人工智能·pytorch·python·numpy·matplotlib·空间计算·scipy