当前位置:网站首页>Data Analysis 5
Data Analysis 5
2022-08-01 07:28:00 【towards the sun.178】
目录
numpy数组:
创建数组
t1=np.array([1,2,3,])
t2=np.arange(2,5)
print(t2)
print(t1)
print(type(t1))

数据类型
t4=np.array(range(1,4),dtype=int)
print(t4)
print(t4.dtype)

调整数据类型
t5=t4.astype("float")
print(t5)
print(t5.dtype)
小数
t6=np.array([random.random() for i in range(10)])
print(t6)
t7=np.round(t6,2)
print(t7)

数组形状
t8=np.arange(12)
t9=t8.reshape(3,4)
print(t9)
数组计算
t10=np.array([[0,1,2,3],
[5,6,7,8],
[10,11,12,13]])
print(t10+2)
print(t10+t9)
numpy读取数据:
us_file_path="D:\\python\\5.数据分析\\US"
u1=np.loadtxt(us_file_path,delimiter=",",dtype=int)
print(u1)![]()


数据转置
u2=u1.transpose()
print(u2)
print('\n')
numpy数组取值:
取行
#取行
print(u1[2])
#取连续多行
print(u1[1:])
#取不连续多行
print(u1[[0,2]]) ![]()

取列
#取列
print(u1[1,:])
#取连续的多列
print(u1[:,1:])
#取不连续的多列
print(u1[:,[0,2]])
print("---------------")

取特定值
#Take the value of the third row and the fourth column
print(u1[3,4])
#取第三行到第五行,The results from the second to third columns
print(u1[2:4,1:4])
#取多个不相邻的点
print(u1[[0,2,2],[0,1,3]])
numpy数值的修改:
布尔索引
#布尔索引
u1[u1<200]=100
print(u1)
三元运算符
u3=np.where(u1<200,0,100)#小于200的数字变成0,否则变成100
print(u3)内置函数clip
u4=u1.clip(300,400)#小于300的赋值给300,大于400的赋值给400
print(u4)

边栏推荐
- 插入排序—直接插入排序和希尔排序
- mysql中添加字段的相关问题
- Electromagnetic compatibility introductory tutorial (6) test project
- 爆肝3万字,最硬核丨Mysql 知识体系、命令全集 【建议收藏 】
- VoLTE基础学习系列 | 企业语音网简述
- Delphi MDI appliction 文档最大化显示、去掉最大化最小化等按钮
- datagrip 报错 “The specified database userpassword combination is rejected...”的解决方法
- 我说过无数遍了:从来没有一种技术是为灵活组合这个目标而设计的
- 支付宝如何生成及配置公钥证书
- GO错误处理方式
猜你喜欢

爬虫框架 Scrapy 详解

Practical training Navicat Chinese and English mode switching

Image lossless compression software which works: try completely free JPG - C image batch finishing compression reduces weight tools | latest JPG batch dressing tools download

22牛客多校1 J.Serval and Essay (启发式合并)

MVVM项目开发(商品管理系统一)

LabVIEW RT中的用户界面更新速度

我三本学历,五面阿里,被面试官“供”着出来了,拿了33*15的Offer

sum of special numbers

图片无损压缩软件哪个好用:试试完全免费的JPG-C 图片批量修整压缩减肥工具吧 | 最新jpg批量修整工具下载

Golang:go开启web服务
随机推荐
Golang:go连接和使用mysql
POJ1287联网题解
Go supports OOP: use struct instead of class
C语言学习概览(二)
如何使用Photoshop合成星轨照片,夜空星轨照片后期处理方法
研发过程中的文档管理与工具
对于升级go1.18的goland问题
gethostbyname \ getaddrinfo 解析域名IP地址不安全的原因
The use of Golang: go template engine
安装SQL Server详细教程
2022杭电多校第二场1011 DOS Card(线段树)
图像基本操作的其他内容
JVM:运行时数据区-PC寄存器(程序计数器)
Vim三种模式
Golang: go open web service
VSCode插件推荐(Rust环境)
22牛客多校1 J.Serval and Essay (启发式合并)
爆肝3万字,最硬核丨Mysql 知识体系、命令全集 【建议收藏 】
Srping bean in the life cycle
我三本学历,五面阿里,被面试官“供”着出来了,拿了33*15的Offer

