当前位置:网站首页>数据分析6
数据分析6
2022-08-01 07:18:00 【朝着阳光.178】
目录
numpy常用统计函数
#均值
print(np.mean(u4,axis=1))
#中值
print(np.median(u4))
#极值
print(np.ptp(u4))
#标准差
print(np.std(u4))
数组拼接
t1=np.arange(0,12).reshape(2,6)
t2=np.arange(12,24).reshape(2,6)
t3=np.vstack((t1,t2))#水平拼接
t4=np.hstack((t1,t2))#竖直拼接
print(t3)
print(t4)
numpy特殊数组的构造方法
2行3列全为0的数组
t5=np.zeros((2,3))
print(t5)
对角线为1
t6=np.eye((3))#3行3列
print(t6)
t6[t6==1]=-1
print(t6)
随机数
print(np.random.randint(10,20,(4,5)))
生成的随机数不变
np.random.seed(1)
print(np.random.randint(0,20,(3,4)))
nan
nan的定义
nan(not a numb):不是一个数字,每个nan是不同的,并且nan属于float类型
判断nan的个数
np.count_nonzero(t!=t)
np.isnan(t)如何将nan替换成均值
def fill_narray(t1):
for i in range(t1.shape[1]):
temp_col=t1[:,i]
nan_num=np.count_nonzero(temp_col!=temp_col)#统计nan的个数
if nan_num!=0:
temp_not_nan_col=temp_col[temp_col==temp_col]
temp_col[np.isnan(temp_col)]=temp_not_nan_col.mean()
return t1t1=np.arange(12).reshape(3,4).astype("float")
t1[1,2:]=np.nan
print(t1)
t2=fill_narray(t1)
print(t2)
边栏推荐
猜你喜欢

"By sharing" northwestern university life service | | bytes a second interview on three sides by HR

小程序通过云函数操作数据库【使用get取数据库】

特殊的日子,值得纪念

LabVIEW中局部变量和全局变量的分配

第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】

VSCode插件推荐(Rust环境)

实战演练 Navicat 中英文模式切换

聊一聊ICMP协议以及ping的过程

Offer brush questions - 1

matlab wind speed model wavelet filtering
随机推荐
return;代表含义
【视觉SLAM十四讲】第一章理论详解
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
POJ2031空间站题解
Golang: go static file processing
Golang: go open web service
MVVM project development (commodity management system 1)
sum of special numbers
Bean的生命周期
Offer刷题——1
POJ1287联网题解
LabVIEW RT中的用户界面更新速度
特殊的日子,值得纪念
Upgrade to heavyweight lock, lock reentrancy will lead to lock release?
仿牛客网项目总结
图像基本操作的其他内容
从底层结构开始学习FPGA(6)----分布式RAM(DRAM,Distributed RAM)
国内外最顶级的8大plm项目管理系统
rhcsa 第四天
并发编程13-JUC之CountDownLatch