当前位置:网站首页>numpy入门详细代码
numpy入门详细代码
2022-08-04 15:11:00 【看星河的兔子】
numpy的核心特征就是n维数组对象——ndarray。可以把它理解为python中一个快速、灵活的大型数据集容器。
以下代码我均用jupyter演示。
生成小的随机数组
import numpy as np
data=np.random.randn(2,3)
data
array([[ 0.60329533, -0.2737639 , -0.49368031],
[-1.90929005, 1.32314732, 0.51238388]])
属性
数组具有dtype属性与shape属性
data.shape
data.dtype

生成ndarray
data1=[6,7.5,8,0,1]
arr1=np.array(data1)
arr1

维度

zeros创造全0数组,ones创造全1数组,empty创造无初始值的数组
类型转换
显示转换astype
数组算术
这一块比较简单,不详细介绍。
基础索引和切片

上面内容比较简单,下面讲切片。

索引举例,按行列寻找理解即可
copy使用
理解为复制即可
数组切片索引
还是比较容易理解的

数组转置

面向数组编程
meshgrid函数接收两个一维数组,并转化为二维矩阵。
条件逻辑转为数组操作
where函数可根据True或者False值进行数组替换
随机漫步示例



边栏推荐
- Next -19- 开启fancybox查看图片大图
- 2022杭电多校3
- 你以为在做的是微服务?不!你做的只是分布式单体!
- 【历史上的今天】8 月 4 日:第一位图灵奖女性得主;NVIDIA 收购 MediaQ;首届网络安全挑战大赛完成
- Win10无法访问移动硬盘怎么解决
- Zheng Qing freshmen school competition and middle-aged engineering selection competition
- vim 常用操作命令
- 基于 Next.js实现在线Excel
- 小程序|炎炎夏日、清爽一夏、头像大换装
- Google plug-in. Download contents file is automatically deleted after solution
猜你喜欢

2022年7月国产数据库大事记-墨天轮

本周讨论用户体验:Daedalus 的 Nemo 加入 Ambire,探索加密海洋

大众点评搜索相关性技术探索与实践
小程序|炎炎夏日、清爽一夏、头像大换装

JCMsuite应用:倾斜平面波传播透过光阑的传输

杭电校赛(逆袭指数)

1401 - Web technology 】 【 introduction to graphical Canvas

【北亚数据恢复】IBM System Storage存储lvm信息丢失数据恢复方案

Bluetooth Technology|In the first half of the year, 1.3 million charging piles were added nationwide, and Bluetooth charging piles will become the mainstream of the market

leetcode: 212. Word Search II
随机推荐
本周讨论用户体验:Daedalus 的 Nemo 加入 Ambire,探索加密海洋
leetcode: 241. Designing precedence for arithmetic expressions
7 天找个 Go 工作,Gopher 要学的条件语句,循环语句 ,第3篇
leetcode:241. 为运算表达式设计优先级
Go 语言快速入门指南: 变量和常量
Jupyter常用操作总结(强烈建议收藏,持续更新实用操作)
Compound Refractive Lenses for X-ray Focusing
【Today in History】August 4: First female Turing Award winner; NVIDIA acquires MediaQ; first Cybersecurity Challenge completed
小程序|炎炎夏日、清爽一夏、头像大换装
C# 将dll打包到程序中
全球电子产品需求放缓,三星手机越南工厂每周只需要干 3~4 天
vim common operation commands
1401 - Web technology 】 【 introduction to graphical Canvas
Win10无法访问移动硬盘怎么解决
C语言写简单三子棋
明明加了唯一索引,为什么还是产生重复数据?
Codeforces Round #811 A~F
【云原生 | 从零开始学Kubernetes】kubernetes之StatefulSet详解
leetcode: 253. How many meeting rooms are required at least
2022年7月国产数据库大事记-墨天轮