当前位置:网站首页>Numpy基础学习
Numpy基础学习
2022-07-27 05:13:00 【派大星的最爱海绵宝宝】
numpy底层使用c语言,围绕数组进行计算,默认64位浮点数
np.array()

np.zeros()

np.ones()

np.shape()

np.arange()

np.random.rand()

转换数据类型
1.创建时
b=np.zeros((2,3),dtype=np.int32)

np.int8/16/32/64
np.uint8/16/32/64
np.float32/64
bool
str
2.已创建
a=a.astype(int)
基本运算
1.四则运算
相同尺寸:
a=np.array([1,2,3,4])
b=np.array([5,4,3,2])

不同尺寸:
a=np.array([[1],
[2]])
b=np.array([5,4])

把a数组由
| 1 |
| 2 |
扩展成
| 1 | 1 |
| 2 | 2 |
2.其他数学运算
平方根,对数运算,指数运算,正弦等
np.sqrt(a)
np.log(a)
np.pow(a,3)
np.sin(a)
筛选元素
b[(b>3)&(b%2==0)]

a=np.array([[1,2],[3,4]])
a[1,:]

典型应用-图片处理
1.读取图片
from PIL import Image
im=Image.open('F:\\桌面\\flower.jpg')
im.show
2.将图片转换成数组
im=np.array(im)
im.shape

3.剪裁图片
im1=np.array(Image.open('F:\\桌面\\flower.jpg'))
im2=np.array(Image.open('F:\\桌面\\yellow.jpg'))
im1_cropped=im1[:600,:1000,:]
im2_cropped=im2[:600,:1000,:]
Image.fromarray(im1_cropped).show()
Image.fromarray(im2_cropped).show()

4.将两张图片混合
im_blend=im1_cropped*0.2+im2_cropped*0.5
im_blend=im_blend.astype(np.uint8)
Image.fromarray(im_blend).show()

5.翻转图片
im1_fliepped=im1[::-1,:,:]
Image.fromarray(im1_fliepped).show()

边栏推荐
猜你喜欢

How can I get the lowest handling charge for opening a futures account?

How to open a general commodity futures account

根据文本自动生成UML时序图(draw.io格式)

PHP 实现与MySQL的数据交互

Minio8.x version setting policy bucket policy

How can seektiger go against the cold air in the market?

Inno setup package jar + H5 + MySQL + redis into exe

Minimum handling charges and margins for futures companies

Dimitra and ocean protocol interpret the secrets behind agricultural data

11.感知机的梯度推导
随机推荐
【MVC架构】MVC模型
Day 15. Deep learning radiomics can predict axillary lymphnode status in early-stage breast cancer
NFT new paradigm, okaleido innovation NFT aggregation trading ecosystem
If you encounter oom online, how to solve it?
Mysql分组后时并行统计数量
19.上下采样与BatchNorm
If the interviewer asks you about JVM, the extra answer of "escape analysis" technology will give you extra points
Day14. 用可解释机器学习方法鉴别肠结核和克罗恩病
RK3288板卡HDMI显示uboot和kernel的logo图片
GBASE 8C——SQL参考6 sql语法(4)
使用Docker部署Redis进行高可用主从复制
MySQL快速比较数据库表数据
舆情&传染病时空分析文献阅读笔记
GBase 8c技术特点
【并发编程系列9】阻塞队列之PriorityBlockingQueue,DelayQueue原理分析
DDD领域驱动设计笔记
Web3 traffic aggregation platform starfish OS interprets the "p2e" ecosystem of real business
MySQL limit分页查询优化实践
dbswitch数据迁移数据增量时如何不覆盖目标源数据
Build a complete system in the maker education movement
