当前位置:网站首页>数据分析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 t1
t1=np.arange(12).reshape(3,4).astype("float")
t1[1,2:]=np.nan
print(t1)
t2=fill_narray(t1)
print(t2)
边栏推荐
猜你喜欢
The BP neural network based on MATLAB voice characteristic signal classification
The log causes these pits in the thread block, you have to prevent
配置我的kitty
curl (7) Failed connect to localhost8080; Connection refused
Vim扩展内容
Matlab simulink particle swarm optimization fuzzy pid control motor pump
NIO programming
How to generate and configure public key certificate in Alipay
目标检测概述-上篇
Practical training Navicat Chinese and English mode switching
随机推荐
奇葩问题 npm install 报错 gyp ERR
自制一款远程控制软件——VeryControl
插入排序—直接插入排序和希尔排序
Vim扩展内容
C语言学习概览(二)
爬虫基本原理介绍、实现以及问题解决
七夕来袭——属于程序员的浪漫
dbeaver连接MySQL数据库及错误Connection refusedconnect处理
Sound Signal Processing Fundamental Frequency Detection and Time-Frequency Analysis
GO错误处理方式
05-SDRAM:仲裁
sum of special numbers
Electromagnetic compatibility introductory tutorial (6) test project
日志导致线程Block的这些坑,你不得不防
my creative day
史上超强最常用SQL语句大全
pytest接口自动化测试框架 | 执行失败跳转pdb
Detailed explanation of the crawler framework Scrapy
牛客刷SQL---2
Summary of test points about app updates in different ways