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)) 

运行效果图:

相关推荐
laocooon5238578861 小时前
对传入的 x , y 两个数组做折线图, x 对应 x 轴, y 对应 y 轴。并保存到 Task1/image1/T2.png
python·numpy·pandas·matplotlib
中科院提名者1 天前
KNN实战进阶:模型评估、Scikit-learn实现与Numpy手动编码
python·numpy·scikit-learn
Maxwell_li11 天前
新冠检测例子学习查准率和召回率
学习·机器学习·数据分析·回归·numpy·pandas
渡我白衣1 天前
Python 与数据科学工具链入门:NumPy、Pandas、Matplotlib 快速上手
人工智能·python·机器学习·自然语言处理·numpy·pandas·matplotlib
Amber_372 天前
数据分析之(MySQL+普通程序) VS (Python的NumPy/Pandas)
python·mysql·数据分析·numpy·pandas
癫狂的兔子6 天前
【Python】【NumPy】学习笔记
python·学习·numpy
MarkHD6 天前
智能体在车联网中的应用:第12天 Python科学计算双雄:掌握NumPy与Pandas,筑牢AI与自动驾驶数据基石
人工智能·python·numpy
Lucky高8 天前
NumPy库实践5_输入和输出
numpy
木童6628 天前
Ansible
numpy
paopao_wu8 天前
深度学习1:Python基础库NumPy与Matplotlib
python·深度学习·numpy