当前位置:网站首页>数据分析5
数据分析5
2022-08-01 07:18:00 【朝着阳光.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("---------------")

取特定值
#取第三行第四列的值
print(u1[3,4])
#取第三行到第五行,第二列到第三列的结果
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)

边栏推荐
- Self-made a remote control software - VeryControl
- The use of Golang: go template engine
- mysql中添加字段的相关问题
- pytest接口自动化测试框架 | 执行失败跳转pdb
- special day to remember
- JSON 与 JS 对象的区别
- datagrip 报错 “The specified database userpassword combination is rejected...”的解决方法
- 第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】
- 太厉害了,终于有人能把文件上传漏洞讲的明明白白了
- LeetCode 0149. Maximum number of points on a line
猜你喜欢

Golang:go获取url和表单属性值

仿牛客网项目总结

Information system project managers must recite the work of the core test site (56) Configuration Control Board (CCB)

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

LevelSequence源码分析

NIO编程

牛客刷SQL---2

Fist game copyright-free music download, League of Legends copyright-free music, can be used for video creation, live broadcast

小程序全面屏手势配置案例

支付宝如何生成及配置公钥证书
随机推荐
Json对象和Json字符串的区别
Why is the lightweight VsCode used more and more?Why eat my C drive 10G?How to Painlessly Clean VsCode Cache?Teach you how to lose weight for C drive
仿牛客网讨论社区项目—项目总结及项目常见面试题
Electromagnetic compatibility introductory tutorial (6) test project
Using FiddlerScript caught poly FiddlerScript 】 【 download
05-SDRAM: Arbitration
测试工具(四)Jenkins环境搭建与使用
matlab wind speed model wavelet filtering
图片无损压缩软件哪个好用:试试完全免费的JPG-C 图片批量修整压缩减肥工具吧 | 最新jpg批量修整工具下载
app 自动化 通过工具查看app 元素 (三)
Dart 异常详解
Does flinkcdc have any solution for mysql's date field type conversion?
七夕来袭——属于程序员的浪漫
如何使用Photoshop合成星轨照片,夜空星轨照片后期处理方法
Xiaobai's 0 Basic Tutorial SQL: An Overview of Relational Databases 02
Motion analysis and parameter optimization of crank-slider mechanism
对于升级go1.18的goland问题
LeetCode 0150. Reverse Polish Expression Evaluation
自制一款远程控制软件——VeryControl
爬虫框架 Scrapy 详解

