当前位置:网站首页>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)

边栏推荐
- curl (7) Failed connect to localhost8080; Connection refused
- 自制一款远程控制软件——VeryControl
- 2022杭电多校第二场1011 DOS Card(线段树)
- 目标检测概述-上篇
- How to generate and configure public key certificate in Alipay
- Self-made a remote control software - VeryControl
- Offer刷题——1
- 支付宝如何生成及配置公钥证书
- LeetCode Question of the Day (309. Best Time to Buy and Sell Stock with Cooldown)
- 七夕来袭——属于程序员的浪漫
猜你喜欢
随机推荐
爆肝3万字,最硬核丨Mysql 知识体系、命令全集 【建议收藏 】
Classwork (7) - #598. remainder operation (mod)
Golang: go to connect and use mysql
LeetCode Question of the Day (309. Best Time to Buy and Sell Stock with Cooldown)
旋度(7)连接失败localhost8080;连接拒绝了
Srping中bean的生命周期
crypto-js uses
Introduction to the basic principles, implementation and problem solving of crawler
flink sql-client,怎么处理源端与目标增加端,sql-client包括映射表与JOB如
JVM:运行时数据区-PC寄存器(程序计数器)
Golang:go模版引擎的使用
目标检测概述-上篇
C语言学习概览(二)
配置我的kitty
NIO编程
金山打字通 官网 下载
R语言使用tidyquant包的tq_transmute函数计算持有某只股票的天、月、周收益率、ggplot2使用条形图可视化股票月收益率数据、使用百分比显示Y轴坐标数据、使用不同的色彩表征正负收益率
我的创作纪念日
rhcsa 第四天
搜索框字符自动补全



![Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]](/img/7f/08b323ffc5b5f8e3354bee6775b994.png)







