当前位置:网站首页>Data Analysis 6
Data Analysis 6
2022-08-01 07:27:00 【Toward the sun. 178】
目录
编辑numpyConstructor for special arrays
The generated random number does not change
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)
numpyConstructor for special arrays
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)))
The generated random number does not change
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)
边栏推荐
猜你喜欢
仿牛客网讨论社区项目—项目总结及项目常见面试题
mysql中添加字段的相关问题
USB 协议 (二) 术语
Golang:go开启web服务
Practical training Navicat Chinese and English mode switching
How to generate and configure public key certificate in Alipay
How to use Photoshop to composite star trail photos, post-processing method of night sky star trail photos
Golang:go模版引擎的使用
【HDLBits 刷题】Circuits(1)Combinational Logic
第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】
随机推荐
聊一聊ICMP协议以及ping的过程
企业员工人事管理系统(数据库课设)
Practical training Navicat Chinese and English mode switching
微信小程序请求封装
目标检测概述-上篇
零代码网站开发利器:WordPress
最小生成树
JVM: Runtime Data Area - PC Register (Program Counter)
Datagrip error "The specified database userpassword combination is rejected..."Solutions
【ASWC Arxml结构分解】-7-Explicit(显式)和Implicit(隐式) Sender-Receiver communication描述差异
Dart 异常详解
VoLTE基础学习系列 | 企业语音网简述
安装SQL Server详细教程
Offer brush questions - 1
选择排序—直接选择排序和堆排序
MATLAB program design and application of MATLAB 2.5
类似 MS Project 的项目管理工具有哪些
从零开始—仿牛客网讨论社区项目(一)
自制一款远程控制软件——VeryControl
仿牛客网讨论社区项目—项目总结及项目常见面试题