当前位置:网站首页>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)
边栏推荐
- Microsoft proposed CodeT: a new SOTA for code generation, with 20 points of performance improvement
- 手写一个博客平台~第一天
- go : gin 自定义日志输出格式
- Vim技巧:永远显示行号
- 零基础学习CANoe Panel(12)—— 进度条(Progress Bar)
- 好友让我看这段代码
- 工业互联网的内涵及其应用
- 使用vsftpd服务传输文件(匿名用户认证、本地用户认证、虚拟用户认证)
- [machine learning] experimental notes - emotion recognition
- 【GCN】《Adaptive Propagation Graph Convolutional Network》(TNNLS 2020)
猜你喜欢

【历史上的今天】7 月 25 日:IBM 获得了第一项专利;Verizon 收购雅虎;亚马逊发布 Fire Phone

Brpc source code analysis (III) -- the mechanism of requesting other servers and writing data to sockets

0713RHCSA

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

【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享

并发编程 — 内存模型 JMM

零基础学习CANoe Panel(12)—— 进度条(Progress Bar)

【CSDN 年终总结】结束与开始,一直在路上—— “1+1=王”的2021总结

【CTR】《Towards Universal Sequence Representation Learning for Recommender Systems》 (KDD‘22)

cv2.resize函数报错:error: (-215:Assertion failed) func != 0 in function ‘cv::hal::resize‘
随机推荐
Chapter5 : Deep Learning and Computational Chemistry
Word style and multi-level list setting skills (II)
Any time, any place, super detective, seriously handle the case!
一味地做大元宇宙的规模,已经背离了元宇宙本该有的发展逻辑
全球都热炸了,谷歌服务器已经崩掉了
B树和B+树
【AI4Code】《Unified Pre-training for Program Understanding and Generation》 NAACL 2021
并发编程 — 内存模型 JMM
Shell common script: judge whether the file of the remote host exists
Shell common script: get the IP address of the network card
【GCN-RS】Towards Representation Alignment and Uniformity in Collaborative Filtering (KDD‘22)
Mlx90640 infrared thermal imager temperature sensor module development notes (V)
ORAN专题系列-21:主要的玩家(设备商)以及他们各自的态度、擅长领域
手写一个博客平台~第一天
【AI4Code】《IntelliCode Compose: Code Generation using Transformer》 ESEC/FSE 2020
The larger the convolution kernel, the stronger the performance? An interpretation of replknet model
vim基础操作汇总
[ai4code final chapter] alphacode: competition level code generation with alphacode (deepmind)
[CSDN year-end summary] end and start, always on the way - "2021 summary of" 1+1= Wang "
conda常用命令:安装,更新,创建,激活,关闭,查看,卸载,删除,清理,重命名,换源,问题