当前位置:网站首页>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值进行数组替换
随机漫步示例



边栏推荐
猜你喜欢

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

HarePoint Analytics for SharePoint Online

MySQL优化学习笔记

leetcode: 250. Count subtrees of equal value

FRED Application: Capillary Electrophoresis System

性能提升400倍丨外汇掉期估值计算优化案例

1403. Minimum Subsequence in Non-Increasing Order

uni-app 从零开始-生命周期(二)

QT笔记——Q_INVOKABLE了解

普法教育结合VR全景,直观感受和学习法治精神
随机推荐
FTP协议抓包-工具wireshark与filezilla
OAID是什么
leetcode:241. 为运算表达式设计优先级
宣传海报
I love Tanabata hahaha
leetcode:254. 因子的组合
Basic Introduction for PLSQL
Go 语言快速入门指南: 变量和常量
C# 判断文件编码
##ansible自动化运维架构与简介
Redis-哨兵模式
leetcode:212. 单词搜索 II
Legal education combined with VR panorama, intuitively feel and learn the spirit of the rule of law
Find My技术|防止你的宠物跑丢,苹果Find My技术可以帮到你
Next -20- 使用自定义样式 (custom style)
基本介绍PLSQL
微软表示将向内部网络安全专家共享数据 为企业提供更安全保护
【Today in History】August 4: First female Turing Award winner; NVIDIA acquires MediaQ; first Cybersecurity Challenge completed
多线程编程之优先级翻转问题
7 天能找到 Go 工作吗?学学 Go 数组和指针试试