NumPy API详解大全(持续更新ing...)

简介: NumPy API详解大全(持续更新ing...)

1. Array Objects


1.1 The N-dimensional array ( ndarray )

1.1.1 numpy.ndarray

  • shape:由array每一维度组成的tuple

如果想要改变array维度,可以直接改变shape,但是不建议这么干

image.png

https://numpy.org/doc/stable/reference/generated/numpy.ndarray.shape.html


  • mean() 等如numpy.mean()


2. Constants


3. Universal Functions (ufunc)


4. Routines


4.1 Array creation routines

  • array(object):创建一个值与object相同的numpy.ndarray对象(元素保持最高精度)

image.png


4.2 Array manipulation routines

https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html

常见问题:入参ndarray必须用稠密矩阵,如果使用了稀疏矩阵,将会报ValueError: zero-dimensional arrays cannot be concatenated bug


4.3 Binary operations


4.4 String operations


4.5 C-Types Foreign Function Interface (numpy.ctypeslib)


4.6 Datetime Support Functions


4.7 Data type routines


4.8 Optionally SciPy-accelerated routines (numpy.dual)


4.9 Mathematical functions with automatic domain (numpy.emath)


4.10 Floating point error handling


4.11 Discrete Fourier Transform (numpy.fft)


4.12 Functional programming


4.13 NumPy-specific help functions


4.14 Indexing routines


4.15 Input and output


4.16 Linear algebra (numpy.linalg)


4.17 Logic functions


4.18 Masked array operations


4.19 Mathematical functions


4.20 Matrix library (numpy.matlib)


4.21 Miscellaneous routines


4.22 Padding Arrays


4.23 Polynomials


4.24 Random sampling (numpy.random)

https://numpy.org/doc/stable/reference/random/index.html


  • Generator

https://numpy.org/doc/stable/reference/random/generator.html

Generator是代替RandomState的。

  1. numpy.random.default_rng()

参数:seed{None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional


示例代码:

import numpy as np
rng = np.random.default_rng(12345)
rfloat = rng.random()
#生成一个随机float
rints = rng.integers(low=0, high=10, size=3)
#生成0(包含)-10(不包含)之间的3个integer


  • Generator.choice(a, size=None, replace=True, p=None, axis=0, shuffle=True)

https://numpy.org/doc/stable/reference/random/generated/numpy.random.Generator.choice.html

从传入的一维数组(a)中产生随机抽样

参数:

size {int, tuple[int]}, optional:输出的shape

replace bool, optional:有放回抽样 / 无放回抽样


示例代码:

①从np.arange(5)中生成一个大小为3的抽样

rng.choice(5, 3)
#输出:array([0, 3, 4]) # random
#This is equivalent to rng.integers(0,5,3)


4.24 Set routines

  • numpy.unique(arr):直接的默认返回值是np.ndarray对象,arr中唯一值从小到大排序

https://numpy.org/doc/stable/reference/generated/numpy.unique.html


4.25 Sorting, searching, and counting


4.26 Statistics

  • numpy.mean(a):直接求整个array-like对象的平均值

https://numpy.org/doc/stable/reference/generated/numpy.mean.html


其他


  • 切片:

按标准来将ndarray变成布尔张量:example_matrix[example_matrix>=0.98]

其他正文及脚注未提及的参考资料


相关文章
|
8月前
|
索引 Python
数据科学:Numpy、Pandas、Matplotlib学习(更新ing...)
数据科学:Numpy、Pandas、Matplotlib学习(更新ing...)
73 0
|
2月前
|
Linux API C语言
【Linux网络的POSIX API】持续更新中
【Linux网络的POSIX API】持续更新中
|
机器学习/深度学习 JSON 编解码
|
JSON JavaScript 前端开发
JQuery常用API(未完,持续更新)
JQuery常用API(未完,持续更新)
JQuery常用API(未完,持续更新)
|
API Python
全网首发:warning: #warning “Using deprecated NumPy API, disable it by “ “#defining NPY_NO_DEPRECATED_API
全网首发:warning: #warning “Using deprecated NumPy API, disable it by “ “#defining NPY_NO_DEPRECATED_API
219 0
|
API 索引 Python
Python3常用其他API速查手册(持续更新ing...)
Python3常用其他API速查手册(持续更新ing...)
Python3常用其他API速查手册(持续更新ing...)
|
机器学习/深度学习 运维 并行计算
PyTorch Python API详解大全(持续更新ing...)(下)
PyTorch Python API详解大全(持续更新ing...)(下)
PyTorch Python API详解大全(持续更新ing...)(下)
|
存储 机器学习/深度学习 自然语言处理
PyTorch Python API详解大全(持续更新ing...)(上)
PyTorch Python API详解大全(持续更新ing...)
PyTorch Python API详解大全(持续更新ing...)(上)
|
存储 编译器 API
OpenGL ES Shader相关API 总结【4】—— GLSL 语法小结【持续更新】
OpenGL ES Shader相关API 总结【4】—— GLSL 语法小结【持续更新】
277 0
OpenGL ES Shader相关API 总结【4】—— GLSL 语法小结【持续更新】
|
前端开发 .NET API
Asp.Net Web API 2 官网菜鸟学习系列导航[持续更新中]
原文:Asp.Net Web API 2 官网菜鸟学习系列导航[持续更新中] 前言 本来一直参见于微软官网进行学习的, 官网网址http://www.asp.net/web-api。出于自己想锻炼一下学习阅读英文文章的目的,又可以学习下微软新发布的技术,其实也很久了,但自己菜鸟一枚,对自己来说都是新技术了。
1619 0