1. 传统编程
scores = [78,45,76,23,90]
#求个数
print(len(scores))
#求平均分
print(sum(scores)/len(scores))
#求最大值、最小值
print(max(scores))
print(min(scores))
#给每个同学加5分
print([score+5 for score in scores])
2. 科学计算
向量化计算
矩阵计算
高性能计算
线性代数
Numpy:
科学计算神器
通用科学计算库
深度学习框架PyTorch,本质上是一个NumPy++
胶水语言,适合快速搭建项目和工程
容器:存储数据的一种格式,NDArray N维数组
算法:各种数据处理算法
将数据放到科学计算的容器里,再去调用科学计算的相关方法。
我们现在写的不是代码,都是数学,底层跑的都是C++。
"""
2. 科学计算
"""
import numpy as np
scores = [78,45,76,23,90]
arr = np.array(scores)
print(arr)
print(arr.size)
print(arr.mean())
print(arr.var())
print(arr.max())
print(arr.std())
print(arr+5)
arr + 5,简单的将每个元素加5。这属于广播机制,自动对齐,通过简单的行或列的复制,对齐形状,直接进行点对点计算。
随机数的概念
#连续均匀分布[0,1)
np.random.rand() #随机数盲盒
# 连续均匀分布[0,1)
np.random.rand() #随机数盲盒
# 离散均匀分布[low,high),在[0,101)之间区30个整数
np.random.randint(low=0,high=101,size=30)
# n表示normal,是标准正态分布,也叫标准高斯分布,mu=0,sigma=1,
np.random.randn(10)