当前位置:网站首页>Numpy简介和特点(一)
Numpy简介和特点(一)
2022-07-25 13:06:00 【凌冰_】
一、NumPy是什么?
NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库。各种其他的库,如Pandas、Matplotlib和Scikit-learn,都建立在这个令人惊叹的库之上。

数组是元素/值的集合,可以有一个或多个维度。一维数组称为向量,二维数组称为矩阵。
NumPy数组称为ndarray或N维数组,它们存储相同类型和大小的元素。它以其高性能而闻名,并在数组规模不断扩大时提供高效的存储和数据操作。
(1) 下载Anaconda时,NumPy会预先安装。
Anaconda | Anaconda Distribution

(2) 单独安装NumPy,只需在你的终端上键入以下命令:
pip install numpy
需要导入库:
import numpy as np
np实际上是数据科学界使用的NumPy的缩写
二、Numpy Ndarray 对象
nd - N-dimension n个维度
array - 数组
说明了numpy是处理任意维度数据
ndarray 对象是用于存放同类型元素的多维数组。
ndarray 中的每个元素在内存中都有相同存储大小的区域。
创建一个 ndarray 只需调用 NumPy 的 array 函数:
numpy.array(object, dtype = None, copy = True, order = None, subok = False, ndmin = 0)
darray的优势
1、比python_list的效率高,且数据量越大,它们效率相差越大。
2、ndarray不受GIL的限制。GIL是全局解释器锁。可以多线程工作,因此效率非常高
pyhton_list和ndarray的效率对比

darray的缺点
只能存储一种数据类型的数据,因此通用性较差,而列表可以存储非常多的类型的数据,因此python_list的通用性比较好。
三、Numpy创建一维数组
- 传入列表方式
- 传入range生成序列
- 使用numpy自带的np.arange()生成数组
- 使用np.linspace()
四、Numpy创建二维数组
- 列表嵌套转换
- 组合嵌套

3.其他( zeros(全0), ones(全1), empty(空))

五、ndarray基本属性


六、二维数组运算

七、Numpy常见的数据类型


八、ndarray的形状

一维:(4, ) 二维:(2, 3) 三维:(4, 3, 2)
九、Numpy索引和切片

十、Numpy随机数组np.random
均匀分布
np.random.rand(10, 10)创建指定形状(示例为10行10列)的数组(范围在0至1之间)np.random.uniform(0, 10)创建指定范围内的一个数np.random.randint(0, 10)创建指定范围内的一个整数
正态分布
给定均值/标准差/维度的正态分布
np.random.normal(1.75, 0.1, (2, 3))

标准正态分布—-standard normal distribution
标准正态分布又称为u分布,是以0为均值、以1为标准差的正态分布,记为N(0,1)
边栏推荐
- Detailed explanation of the training and prediction process of deep learning [taking lenet model and cifar10 data set as examples]
- 简单了解流
- 【AI4Code】CodeX:《Evaluating Large Language Models Trained on Code》(OpenAI)
- [machine learning] experimental notes - emotion recognition
- OAuth,JWT ,OIDC你们搞得我好乱啊
- Force deduction 83 biweekly T4 6131. The shortest dice sequence impossible to get, 303 weeks T4 6127. The number of high-quality pairs
- 【AI4Code】《Unified Pre-training for Program Understanding and Generation》 NAACL 2021
- 并发编程 — 内存模型 JMM
- conda常用命令:安装,更新,创建,激活,关闭,查看,卸载,删除,清理,重命名,换源,问题
- Brpc source code analysis (III) -- the mechanism of requesting other servers and writing data to sockets
猜你喜欢

B树和B+树

Convolutional neural network model -- lenet network structure and code implementation

ThreadLocal&Fork/Join

Substance Designer 2021软件安装包下载及安装教程

零基础学习CANoe Panel(16)—— Clock Control/Panel Control/Start Stop Control/Tab Control

Excel录制宏

Machine learning strong foundation program 0-4: popular understanding of Occam razor and no free lunch theorem
![[CSDN year-end summary] end and start, always on the way -](/img/51/a3fc5eba0eeb22b600260ee81ff9e6.png)
[CSDN year-end summary] end and start, always on the way - "2021 summary of" 1+1= Wang "

Shell常用脚本:检测某域名、IP地址是否通

R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions
随机推荐
Oran special series-21: major players (equipment manufacturers) and their respective attitudes and areas of expertise
程序的内存布局
mysql函数汇总之日期和时间函数
Redis可视化工具RDM安装包分享
若依如何实现用户免密登录配置方法?
vim基础操作汇总
The larger the convolution kernel, the stronger the performance? An interpretation of replknet model
使用vsftpd服务传输文件(匿名用户认证、本地用户认证、虚拟用户认证)
cv2.resize函数报错:error: (-215:Assertion failed) func != 0 in function ‘cv::hal::resize‘
录制和剪辑视频,如何解决占用空间过大的问题?
[six articles talk about scalablegnn] around www 2022 best paper PASCA
go : gin 自定义日志输出格式
微软提出CodeT:代码生成新SOTA,20个点的性能提升
央行数研所穆长春:数字人民币可控匿名是维护公众利益和金融安全的客观需要
Zero basic learning canoe panel (12) -- progress bar
详解浮点数的精度问题
Django 2 ----- 数据库与Admin
程序员成长第二十七篇:如何评估需求优先级?
Atcoder beginer contest 261e / / bitwise thinking + DP
OAuth, JWT, oidc, you mess me up