This commit is contained in:
estomm
2020-09-25 10:56:54 +08:00
parent fe167ce897
commit 5fcc3ef102
18 changed files with 1574 additions and 0 deletions

View File

@@ -0,0 +1,160 @@
## 基本运算
算术和比较操作ndarrays 被定义为逐元素操作,并且通常将 ndarray对象作为结果产生。
* 算术运算+-*/// %divmod()**,pow()
* 位运算<<,>>&^|~
* 逻辑运算 not,and,or
* 比较运算==<> <=>=!=
* 自等运算+=,-=,*=,/=,//=,%=,**=,<<=,>>=,&=,^=,|=,~=
> 以上所有运算在ndarray中均已经复写实现。
### 比较运算符
方法 | 描述
---|---
[ndarray.\__lt__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__lt__.html#numpy.ndarray.__lt__)(self, value, /) | 返回 self<value.
[ndarray.\__le__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__le__.html#numpy.ndarray.__le__)(self, value, /) | 返回 self<=value.
[ndarray.\__gt__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__gt__.html#numpy.ndarray.__gt__)(self, value, /) | 返回 self>value.
[ndarray.\__ge__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__ge__.html#numpy.ndarray.__ge__)(self, value, /) | 返回 self>=value.
[ndarray.\__eq__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__eq__.html#numpy.ndarray.__eq__)(self, value, /) | 返回 self==value.
[ndarray.\__ne__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__ne__.html#numpy.ndarray.__ne__)(self, value, /) | 返回 self!=value.
### array``bool``)的真值:
方法 | 描述
---|---
[ndarray.\_\_bool__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__bool__.html#numpy.ndarray.__bool__)(self, /) | self != 0
> tip 注意:
数组的真值测试会调用
[``ndarray.\_\_bool__``](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__bool__.html#numpy.ndarray.__bool__)如果数组中的元素数大于1则会引发错误因为此类数组的真值是不明确的。使用[``.any()``](https://numpy.org/devdocs/reference/generated/numpy.ndarray.any.html#numpy.ndarray.any)而
[``.all()``](https://numpy.org/devdocs/reference/generated/numpy.ndarray.all.html#numpy.ndarray.all)不是清楚这种情况下的含义。如果元素数为0则数组的计算结果为``False``。)
### 一元操作
方法 | 描述
---|---
[ndarray.\_\_neg__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__neg__.html#numpy.ndarray.__neg__)(self, /) | -self
[ndarray.\_\_pos__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__pos__.html#numpy.ndarray.__pos__)(self, /) | +self
[ndarray.\_\_abs__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__abs__.html#numpy.ndarray.__abs__)(self) |
[ndarray.\_\_invert__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__invert__.html#numpy.ndarray.__invert__)(self, /) | ~self
### 算术运算
方法 | 描述
---|---
[ndarray.\_\_add__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__add__.html#numpy.ndarray.__add__)(self, value, /) | 返回 self+value.
[ndarray.\_\_sub__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__sub__.html#numpy.ndarray.__sub__)(self, value, /) | 返回 self-value.
[ndarray.\_\_mul__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__mul__.html#numpy.ndarray.__mul__)(self, value, /) | 返回 self*value.
[ndarray.\_\_truediv__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__truediv__.html#numpy.ndarray.__truediv__)(self, value, /) | 返回 self/value.
[ndarray.\_\_floordiv__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__floordiv__.html#numpy.ndarray.__floordiv__)(self, value, /) | 返回 self//value.
[ndarray.\_\_mod__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__mod__.html#numpy.ndarray.__mod__)(self, value, /) | 返回 self%value.
[ndarray.\_\_divmod__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__divmod__.html#numpy.ndarray.__divmod__)(self, value, /) | 返回 divmod(self, value).
[ndarray.\_\_pow__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__pow__.html#numpy.ndarray.__pow__)(self, value[, mod]) | 返回 pow(self, value, mod).
[ndarray.\_\_lshift__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__lshift__.html#numpy.ndarray.__lshift__)(self, value, /) | 返回 self<<value.
[ndarray.\_\_rshift__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__rshift__.html#numpy.ndarray.__rshift__)(self, value, /) | 返回 self>>value.
[ndarray.\_\_and__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__and__.html#numpy.ndarray.__and__)(self, value, /) | 返回 self&value.
[ndarray.\_\_or__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__or__.html#numpy.ndarray.__or__)(self, value, /) | 返回 self|value.
[ndarray.\_\_xor__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__xor__.html#numpy.ndarray.__xor__)(self, value, /) | 返回 self^value.
> tip 注意
- [``pow``](https://docs.python.org/dev/library/functions.html#pow)默认忽略任何第三个参数,
因为底层[``ufunc``](https://numpy.org/devdocs/reference/generated/numpy.power.html#numpy.power)只接受两个参数。
- 三个划分算子都是定义的; ``div``默认情况下``truediv``处于活动状态,
当[``__future__``](https://docs.python.org/dev/library/__future__.html#module-__future__)分割生效时处于活动状态。
- 因为[``ndarray``](https://numpy.org/devdocs/reference/generated/numpy.ndarray.html#numpy.ndarray)是内置类型用C编写
所以 ``__r{op}__`` 不直接定义特殊方法。
- 可以使用调用为数组实现许多算术特殊方法的函数[``__array_ufunc__``](classes.html#numpy.class.__array_ufunc__)。
### 自身算术运算
方法 | 描述
---|---
[ndarray.\_\_iadd__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__iadd__.html#numpy.ndarray.__iadd__)(self, value, /) | 返回 self+=value。
[ndarray.\_\_isub__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__isub__.html#numpy.ndarray.__isub__)(self, value, /) | 返回 self==value。
[ndarray.\_\_imul__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__imul__.html#numpy.ndarray.__imul__)(self, value, /) | 返回 self*=value。
[ndarray.\_\_itruediv__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__itruediv__.html#numpy.ndarray.__itruediv__)(self, value, /) | 返回 self/=value。
[ndarray.\_\_ifloordiv__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__ifloordiv__.html#numpy.ndarray.__ifloordiv__)(self, value, /) | 返回 self//=value。
[ndarray.\_\_imod__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__imod__.html#numpy.ndarray.__imod__)(self, value, /) | 返回 self=value。
[ndarray.\_\_ipow__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__ipow__.html#numpy.ndarray.__ipow__)(self, value, /) | 返回 self**=value。
[ndarray.\_\_ilshift__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__ilshift__.html#numpy.ndarray.__ilshift__)(self, value, /) | 返回 self<<=value。
[ndarray.\_\_irshift__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__irshift__.html#numpy.ndarray.__irshift__)(self, value, /) | 返回 self>>=value。
[ndarray.\_\_iand__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__iand__.html#numpy.ndarray.__iand__)(self, value, /) | 返回 self&=value。
[ndarray.\_\_ior__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__ior__.html#numpy.ndarray.__ior__)(self, value, /) | 返回 self|=value。
[ndarray.\_\_ixor__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__ixor__.html#numpy.ndarray.__ixor__)(self, value, /) | 返回 self^=value。
> danger 警告
就地操作将使用由两个操作数的数据类型决定的精度来执行计算,但会悄悄地向下转换结果(如果需要),
以便它可以重新适应数组。
因此,对于混合精度计算,``A {op} = B`` 可以不同于 ``A = A {op} B``。例如,假设 ``a = ones(33)``。
然后,``a += 3j`` 与 ``a = a + 3j`` 不同:当它们都执行相同的计算时,``a += 3`` 将结果强制转换为适合 ``a`` ,而 ``a = a+3j`` 将名称 ``a`` 重新绑定到结果。
### 矩阵乘法
方法 | 描述
---|---
[ndarray.\_\_matmul__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__matmul__.html#numpy.ndarray.__matmul__)(self, value, /) | 返回 [self@value](mailto:self%40value)。
> tip 注意
Matrix 运算符 ``@`` 和 ``@=`` 是在PEP465之后的Python 3.5中引入的。NumPy 1.10.0为测试目的初步实现了 ``@``。
进一步的文档可以在 [``matmul``](https://numpy.org/devdocs/reference/generated/numpy.matmul.html#numpy.matmul) 文档中找到。
## 标准库函数运算
### numpy对下列标准库方法进行了实现。
```py
numpyallanyargmax argminargpartitionargsortchoose clipcompresscopycumprod cumsumdiagonalimagmax meanminnonzeropartition prodptpputravelreal repeatreshaperound searchsortedsortsqueezestd sumswapaxestaketrace transposevar
```
> 标准库函数的运算,基本都进行重写可以运算。
### 复制
方法 | 描述
---|---
[ndarray.\_\_copy__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__copy__.html#numpy.ndarray.__copy__)() | 如果使用的[copy.copy](https://docs.python.org/dev/library/copy.html#copy.copy)是所谓的数组上。
[ndarray.\_\_deepcopy__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__deepcopy__.html#numpy.ndarray.__deepcopy__)() | 如果使用的[copy.deepcopy](https://docs.python.org/dev/library/copy.html#copy.deepcopy)是所谓的数组上。
[ndarray.\_\_reduce__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__reduce__.html#numpy.ndarray.__reduce__)() | 用于 pickling。
[ndarray.\_\_setstate__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__setstate__.html#numpy.ndarray.__setstate__)(州,/ | 用于unpickling。
### 基本定制:
方法 | 描述
---|---
[ndarray.\_\_new__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__new__.html#numpy.ndarray.__new__)(\*args, \*\*kwargs) | 创建并返回一个新对象。
[ndarray.\_\_array__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__array__.html#numpy.ndarray.__array__)() | 如果没有给出dtype则返回对self的新引用;如果dtype与数组的当前dtype不同则返回提供的数据类型的新数组。
[ndarray.\_\_array_wrap__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__array_wrap__.html#numpy.ndarray.__array_wrap__)() |
### 容器定制
方法 | 描述
---|---
[ndarray.\_\_len__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__len__.html#numpy.ndarray.__len__)(self, /) | 返回 len(self)。
[ndarray.\_\_getitem__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__getitem__.html#numpy.ndarray.__getitem__)(self, key, /) | 返回 self[key]。
[ndarray.\_\_setitem__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__setitem__.html#numpy.ndarray.__setitem__)(self, key, value, /) | 将 self[key] 设置为value。
[ndarray.\_\_contains__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__contains__.html#numpy.ndarray.__contains__)(self, key, /) | 返回 self 的 key。
### 转换; 操作``int````float`` 和 ``complex``。
> 它们仅适用于其中包含一个元素的数组,并返回相应的标量。
方法 | 描述
---|---
[ndarray.\_\_int__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__int__.html#numpy.ndarray.__int__)(self) | none
[ndarray.\_\_float__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__float__.html#numpy.ndarray.__float__)(self) | none
[ndarray.\_\_complex__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__complex__.html#numpy.ndarray.__complex__)() | none
### 字符串表示:
方法 | 描述
---|---
[ndarray.\_\_str__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__str__.html#numpy.ndarray.__str__)(self, /) | 返回 str(self)。
[ndarray.\_\_repr__](https://numpy.org/devdocs/reference/generated/numpy.ndarray.__repr__.html#numpy.ndarray.__repr__)(self, /) | 返回 repr(self)。

View File

@@ -0,0 +1,151 @@
# 数学函数(`Mathematical functions`)
## 三角函数
method | description
---|---
[sin](https://numpy.org/devdocs/reference/generated/numpy.sin.html#numpy.sin)(x, /[, out, where, casting, order, …]) | 正弦函数, element-wise.
[cos](https://numpy.org/devdocs/reference/generated/numpy.cos.html#numpy.cos)(x, /[, out, where, casting, order, …]) | 余弦函数 element-wise.
[tan](https://numpy.org/devdocs/reference/generated/numpy.tan.html#numpy.tan)(x, /[, out, where, casting, order, …]) | 正切函数, element-wise.
[arcsin](https://numpy.org/devdocs/reference/generated/numpy.arcsin.html#numpy.arcsin)(x, /[, out, where, casting, order, …]) | 反正弦函数, element-wise.
[arccos](https://numpy.org/devdocs/reference/generated/numpy.arccos.html#numpy.arccos)(x, /[, out, where, casting, order, …]) | 反余弦函数, element-wise.
[arctan](https://numpy.org/devdocs/reference/generated/numpy.arctan.html#numpy.arctan)(x, /[, out, where, casting, order, …]) | 反正切函数, element-wise.
[hypot](https://numpy.org/devdocs/reference/generated/numpy.hypot.html#numpy.hypot)(x1, x2, /[, out, where, casting, …]) | 传入直角三角形的“直角边”,返回其斜边。
[arctan2](https://numpy.org/devdocs/reference/generated/numpy.arctan2.html#numpy.arctan2)(x1, x2, /[, out, where, casting, …]) | x1 / x2的 Element-wise 反正切线正确选择象限。
[degrees](https://numpy.org/devdocs/reference/generated/numpy.degrees.html#numpy.degrees)(x, /[, out, where, casting, order, …]) | 将角度从[弧度](https://numpy.org/devdocs/reference/generated/numpy.radians.html#numpy.radians)转换为度。
radians(x, /[, out, where, casting, order, …]) | 将角度从度转换为弧度。
[unwrap](https://numpy.org/devdocs/reference/generated/numpy.unwrap.html#numpy.unwrap)(p[, discont, axis]) | 通过将值之间的增量更改为2 * pi来展开。
[deg2rad](https://numpy.org/devdocs/reference/generated/numpy.deg2rad.html#numpy.deg2rad)(x, /[, out, where, casting, order, …]) | 将角度从度转换为弧度。
[rad2deg](https://numpy.org/devdocs/reference/generated/numpy.rad2deg.html#numpy.rad2deg)(x, /[, out, where, casting, order, …]) | 将角度从弧度转换为度。
## 双曲函数
method | description
---|---
[sinh](https://numpy.org/devdocs/reference/generated/numpy.sinh.html#numpy.sinh)(x, /[, out, where, casting, order, …]) | 双曲正弦, element-wise.
[cosh](https://numpy.org/devdocs/reference/generated/numpy.cosh.html#numpy.cosh)(x, /[, out, where, casting, order, …]) | 双曲余弦, element-wise.
[tanh](https://numpy.org/devdocs/reference/generated/numpy.tanh.html#numpy.tanh)(x, /[, out, where, casting, order, …]) | 计算双曲正切 element-wise.
[arcsinh](https://numpy.org/devdocs/reference/generated/numpy.arcsinh.html#numpy.arcsinh)(x, /[, out, where, casting, order, …]) | 反双曲正弦 element-wise.
[arccosh](https://numpy.org/devdocs/reference/generated/numpy.arccosh.html#numpy.arccosh)(x, /[, out, where, casting, order, …]) | 反双曲余弦, element-wise.
[arctanh](https://numpy.org/devdocs/reference/generated/numpy.arctanh.html#numpy.arctanh)(x, /[, out, where, casting, order, …]) | 反双曲正切 element-wise.
## 四舍五入
method | description
---|---
[around](https://numpy.org/devdocs/reference/generated/numpy.around.html#numpy.around)(a[, decimals, out]) | 平均舍入到给定的小数位数。
[round_](https://numpy.org/devdocs/reference/generated/numpy.round_.html#numpy.round_)(a[, decimals, out]) | 将数组舍入到给定的小数位数。
[rint](https://numpy.org/devdocs/reference/generated/numpy.rint.html#numpy.rint)(x, /[, out, where, casting, order, …]) | 将数组的元素四舍五入到最接近的整数。
[fix](https://numpy.org/devdocs/reference/generated/numpy.fix.html#numpy.fix)(x[, out]) | 四舍五入为零。
[floor](https://numpy.org/devdocs/reference/generated/numpy.floor.html#numpy.floor)(x, /[, out, where, casting, order, …]) | 返回输入的底限, element-wise.
[ceil](https://numpy.org/devdocs/reference/generated/numpy.ceil.html#numpy.ceil)(x, /[, out, where, casting, order, …]) | 返回输入的上限, element-wise.
[trunc](https://numpy.org/devdocs/reference/generated/numpy.trunc.html#numpy.trunc)(x, /[, out, where, casting, order, …]) | 返回输入的截断值, element-wise.
## 加法函数, 乘法函数, 减法函数
method | description
---|---
[prod](https://numpy.org/devdocs/reference/generated/numpy.prod.html#numpy.prod)(a[, axis, dtype, out, keepdims, …]) | 返回给定轴上数组元素的乘积。
[sum](https://numpy.org/devdocs/reference/generated/numpy.sum.html#numpy.sum)(a[, axis, dtype, out, keepdims, …]) | 给定轴上的数组元素的总和。
[nanprod](https://numpy.org/devdocs/reference/generated/numpy.nanprod.html#numpy.nanprod)(a[, axis, dtype, out, keepdims]) | 返回数组元素在给定轴上的乘积将非数字NaNs视为一个。
[nansum](https://numpy.org/devdocs/reference/generated/numpy.nansum.html#numpy.nansum)(a[, axis, dtype, out, keepdims]) | 返回给定轴上的数组元素的总和将非数字NaNs视为零。
[cumprod](https://numpy.org/devdocs/reference/generated/numpy.cumprod.html#numpy.cumprod)(a[, axis, dtype, out]) | 返回沿给定轴的元素的累加乘积。
[cumsum](https://numpy.org/devdocs/reference/generated/numpy.cumsum.html#numpy.cumsum)(a[, axis, dtype, out]) | 返回沿给定轴的元素的累加和。
[nancumprod](https://numpy.org/devdocs/reference/generated/numpy.nancumprod.html#numpy.nancumprod)(a[, axis, dtype, out]) | 返回数组元素在给定轴上的累积乘积将非数字NaNs视为一个。
[nancumsum](https://numpy.org/devdocs/reference/generated/numpy.nancumsum.html#numpy.nancumsum)(a[, axis, dtype, out]) | 返回在给定轴上将非数字NaNs视为零的数组元素的累积总和。
[diff](https://numpy.org/devdocs/reference/generated/numpy.diff.html#numpy.diff)(a[, n, axis, prepend, append]) | 计算沿给定轴的第n个离散差。
[ediff1d](https://numpy.org/devdocs/reference/generated/numpy.ediff1d.html#numpy.ediff1d)(ary[, to_end, to_begin]) | 数组的连续元素之间的差值。
[gradient](https://numpy.org/devdocs/reference/generated/numpy.gradient.html#numpy.gradient)(f, \*varargs, \*\*kwargs) | 返回N维数组的梯度。
[cross](https://numpy.org/devdocs/reference/generated/numpy.cross.html#numpy.cross)(a, b[, axisa, axisb, axisc, axis]) | 返回两个(数组)向量的叉积。
[trapz](https://numpy.org/devdocs/reference/generated/numpy.trapz.html#numpy.trapz)(y[, x, dx, axis]) | 使用复合梯形规则沿给定轴积分。
## 指数和对数
method | description
---|---
[exp](https://numpy.org/devdocs/reference/generated/numpy.exp.html#numpy.exp)(x, /[, out, where, casting, order, …]) | 计算输入数组中所有元素的指数。
[expm1](https://numpy.org/devdocs/reference/generated/numpy.expm1.html#numpy.expm1)(x, /[, out, where, casting, order, …]) | 为数组中的所有元素计算expx-1。
[exp2](https://numpy.org/devdocs/reference/generated/numpy.exp2.html#numpy.exp2)(x, /[, out, where, casting, order, …]) | 为输入数组中的所有p计算2 ** p。
[log](https://numpy.org/devdocs/reference/generated/numpy.log.html#numpy.log)(x, /[, out, where, casting, order, …]) | 自然对数, element-wise.
[log10](https://numpy.org/devdocs/reference/generated/numpy.log10.html#numpy.log10)(x, /[, out, where, casting, order, …]) | 返回输入数组的以10为底的对数, element-wise.
[log2](https://numpy.org/devdocs/reference/generated/numpy.log2.html#numpy.log2)(x, /[, out, where, casting, order, …]) | x的以2为底的对数。
[log1p](https://numpy.org/devdocs/reference/generated/numpy.log1p.html#numpy.log1p)(x, /[, out, where, casting, order, …]) | 返回元素加一个输入数组的自然对数。
[logaddexp](https://numpy.org/devdocs/reference/generated/numpy.logaddexp.html#numpy.logaddexp)(x1, x2, /[, out, where, casting, …]) | 输入取幂之和的对数。
[logaddexp2](https://numpy.org/devdocs/reference/generated/numpy.logaddexp2.html#numpy.logaddexp2)(x1, x2, /[, out, where, casting, …]) | 以2为底的输入的幂和的对数。
## 其他特殊函数
method | description
---|---
[i0](https://numpy.org/devdocs/reference/generated/numpy.i0.html#numpy.i0)(x) | 第一种修改的Bessel函数阶数为0。
[sinc](https://numpy.org/devdocs/reference/generated/numpy.sinc.html#numpy.sinc)(x) | 返回sinc函数。
## 浮点
method | description
---|---
[signbit](https://numpy.org/devdocs/reference/generated/numpy.signbit.html#numpy.signbit)(x, /[, out, where, casting, order, …]) | 在设置了符号位(小于零)的情况下返回 element-wise True。
[copysign](https://numpy.org/devdocs/reference/generated/numpy.copysign.html#numpy.copysign)(x1, x2, /[, out, where, casting, …]) | 将x1的符号更改为x2的符号, element-wise.
[frexp](https://numpy.org/devdocs/reference/generated/numpy.frexp.html#numpy.frexp)(x[, out1, out2], / [[, out, where, …]) | 将x的元素分解为尾数和二进制指数。
[ldexp](https://numpy.org/devdocs/reference/generated/numpy.ldexp.html#numpy.ldexp)(x1, x2, /[, out, where, casting, …]) | 返回x1 * 2 ** x2, element-wise.
[nextafter](https://numpy.org/devdocs/reference/generated/numpy.nextafter.html#numpy.nextafter)(x1, x2, /[, out, where, casting, …]) | 向x2返回x1之后的下一个浮点值, element-wise.
[spacing](https://numpy.org/devdocs/reference/generated/numpy.spacing.html#numpy.spacing)(x, /[, out, where, casting, order, …]) | 返回x与最近的相邻数字之间的距离。
## 理性例程
method | description
---|---
[lcm](https://numpy.org/devdocs/reference/generated/numpy.lcm.html#numpy.lcm)(x1, x2, /[, out, where, casting, order, …]) | 返回1和x2的最小公倍数
[gcd](https://numpy.org/devdocs/reference/generated/numpy.gcd.html#numpy.gcd)(x1, x2, /[, out, where, casting, order, …]) | 返回x1和x2的最大公约数
## 算术运算
method | description
---|---
[add](https://numpy.org/devdocs/reference/generated/numpy.add.html#numpy.add)(x1, x2, /[, out, where, casting, order, …]) | 按元素添加参数。
[reciprocal](https://numpy.org/devdocs/reference/generated/numpy.reciprocal.html#numpy.reciprocal)(x, /[, out, where, casting, …]) | 以元素为单位返回参数的倒数。
[positive](https://numpy.org/devdocs/reference/generated/numpy.positive.html#numpy.positive)(x, /[, out, where, casting, order, …]) | 数值正, element-wise.
[negative](https://numpy.org/devdocs/reference/generated/numpy.negative.html#numpy.negative)(x, /[, out, where, casting, order, …]) | 数值负数, element-wise.
[multiply](https://numpy.org/devdocs/reference/generated/numpy.multiply.html#numpy.multiply)(x1, x2, /[, out, where, casting, …]) |逐个乘以参数。
[divide](https://numpy.org/devdocs/reference/generated/numpy.divide.html#numpy.divide)(x1, x2, /[, out, where, casting, …]) | 返回输入的真实除法, element-wise.
[power](https://numpy.org/devdocs/reference/generated/numpy.power.html#numpy.power)(x1, x2, /[, out, where, casting, …]) | 第一阵列元素从第二阵列提升为幂, element-wise.
[subtract](https://numpy.org/devdocs/reference/generated/numpy.subtract.html#numpy.subtract)(x1, x2, /[, out, where, casting, …]) | 逐个元素地减去参数。
[true_divide](https://numpy.org/devdocs/reference/generated/numpy.true_divide.html#numpy.true_divide)(x1, x2, /[, out, where, …]) | 返回输入的真实除法, element-wise.
[floor_divide](https://numpy.org/devdocs/reference/generated/numpy.floor_divide.html#numpy.floor_divide)(x1, x2, /[, out, where, …]) | 返回小于或等于输入的除法的最大整数。
[float_power](https://numpy.org/devdocs/reference/generated/numpy.float_power.html#numpy.float_power)(x1, x2, /[, out, where, …]) | 第一阵列元素从第二阵列提升为幂, element-wise.
[fmod](https://numpy.org/devdocs/reference/generated/numpy.fmod.html#numpy.fmod)(x1, x2, /[, out, where, casting, …]) | 返回元素的除法 [remainder](https://numpy.org/devdocs/reference/generated/numpy.remainder.html#numpy.remainder)。
[mod](https://numpy.org/devdocs/reference/generated/numpy.mod.html#numpy.mod)(x1, x2, /[, out, where, casting, order, …]) | 返回元素的除法余数。
[modf](https://numpy.org/devdocs/reference/generated/numpy.modf.html#numpy.modf)(x[, out1, out2], / [[, out, where, …]) | 返回数组的分数和整数部分, element-wise.
remainder(x1, x2, /[, out, where, casting, …]) | 返回元素的除法余数。
[divmod](https://numpy.org/devdocs/reference/generated/numpy.divmod.html#numpy.divmod)(x1, x2[, out1, out2], / [[, out, …]) | 同时返回按元素商和余数。
## 处理复数
method | description
---|---
[angle](https://numpy.org/devdocs/reference/generated/numpy.angle.html#numpy.angle)(z[, deg]) | 返回复杂参数的角度。
[real](https://numpy.org/devdocs/reference/generated/numpy.real.html#numpy.real)(val) | 返回复杂参数的实部。
[imag](https://numpy.org/devdocs/reference/generated/numpy.imag.html#numpy.imag)(val) | 返回复杂参数的虚部。
[conj](https://numpy.org/devdocs/reference/generated/numpy.conj.html#numpy.conj)(x, /[, out, where, casting, order, …]) | 返回 complex [conjugate](https://numpy.org/devdocs/reference/generated/numpy.conjugate.html#numpy.conjugate), element-wise.
[conjugate](https://numpy.org/devdocs/reference/generated/numpy.conjugate.html#numpy.conjugate)(x, /[, out, where, casting, …]) | 返回复共轭, element-wise.
## 杂项
method | description
---|---
[convolve](https://numpy.org/devdocs/reference/generated/numpy.convolve.html#numpy.convolve)(a, v[, mode]) | 返回两个一维序列的离散线性卷积。
[clip](https://numpy.org/devdocs/reference/generated/numpy.clip.html#numpy.clip)(a, a_min, a_max[, out]) | 裁剪(限制)数组中的值。
[sqrt](https://numpy.org/devdocs/reference/generated/numpy.sqrt.html#numpy.sqrt)(x, /[, out, where, casting, order, …]) |返回数组的非负 [平方](https://numpy.org/devdocs/reference/generated/numpy.square.html#numpy.square)根, element-wise.
[cbrt](https://numpy.org/devdocs/reference/generated/numpy.cbrt.html#numpy.cbrt)(x, /[, out, where, casting, order, …]) | 返回数组的立方根, element-wise.
[square](https://numpy.org/devdocs/reference/generated/numpy.square.html#numpy.square)(x, /[, out, where, casting, order, …]) | 返回输入的元素方平方。
[absolute](https://numpy.org/devdocs/reference/generated/numpy.absolute.html#numpy.absolute)(x, /[, out, where, casting, order, …]) | 计算绝对值 element-wise.
[fabs](https://numpy.org/devdocs/reference/generated/numpy.fabs.html#numpy.fabs)(x, /[, out, where, casting, order, …]) | 计算绝对值 element-wise.
[sign](https://numpy.org/devdocs/reference/generated/numpy.sign.html#numpy.sign)(x, /[, out, where, casting, order, …]) | 返回数字符号的逐元素指示。
[heaviside](https://numpy.org/devdocs/reference/generated/numpy.heaviside.html#numpy.heaviside)(x1, x2, /[, out, where, casting, …]) | 计算Heaviside阶跃函数。
[maximum](https://numpy.org/devdocs/reference/generated/numpy.maximum.html#numpy.maximum)(x1, x2, /[, out, where, casting, …]) | 数组元素的逐元素最大值。
[minimum](https://numpy.org/devdocs/reference/generated/numpy.minimum.html#numpy.minimum)(x1, x2, /[, out, where, casting, …]) | 数组元素的按元素最小值。
[fmax](https://numpy.org/devdocs/reference/generated/numpy.fmax.html#numpy.fmax)(x1, x2, /[, out, where, casting, …]) | 数组元素的逐元素最大值。
[fmin](https://numpy.org/devdocs/reference/generated/numpy.fmin.html#numpy.fmin)(x1, x2, /[, out, where, casting, …]) | 数组元素的按元素最小值。
[nan_to_num](https://numpy.org/devdocs/reference/generated/numpy.nan_to_num.html#numpy.nan_to_num)(x[, copy, nan, posinf, neginf]) | 用较大的有限数字默认行为或使用用户定义的nanposinf和/或neginf关键字定义的数字将NaN替换为零和无穷大。
[real_if_close](https://numpy.org/devdocs/reference/generated/numpy.real_if_close.html#numpy.real_if_close)(a[, tol]) | 如果复杂输入接近实数,则返回复杂数组。
[interp](https://numpy.org/devdocs/reference/generated/numpy.interp.html#numpy.interp)(x, xp, fp[, left, right, period]) | 一维线性插值。

View File

@@ -0,0 +1,48 @@
# Statistics
## Order statistics
method | description
---|---
[amin](https://numpy.org/devdocs/reference/generated/numpy.amin.html#numpy.amin)(a[, axis, out, keepdims, initial, where]) | Return the minimum of an array or minimum along an axis.
[amax](https://numpy.org/devdocs/reference/generated/numpy.amax.html#numpy.amax)(a[, axis, out, keepdims, initial, where]) | Return the maximum of an array or maximum along an axis.
[nanmin](https://numpy.org/devdocs/reference/generated/numpy.nanmin.html#numpy.nanmin)(a[, axis, out, keepdims]) | Return minimum of an array or minimum along an axis, ignoring any NaNs.
[nanmax](https://numpy.org/devdocs/reference/generated/numpy.nanmax.html#numpy.nanmax)(a[, axis, out, keepdims]) | Return the maximum of an array or maximum along an axis, ignoring any NaNs.
[ptp](https://numpy.org/devdocs/reference/generated/numpy.ptp.html#numpy.ptp)(a[, axis, out, keepdims]) | Range of values (maximum - minimum) along an axis.
[percentile](https://numpy.org/devdocs/reference/generated/numpy.percentile.html#numpy.percentile)(a, q[, axis, out, …]) | Compute the q-th percentile of the data along the specified axis.
[nanpercentile](https://numpy.org/devdocs/reference/generated/numpy.nanpercentile.html#numpy.nanpercentile)(a, q[, axis, out, …]) | Compute the qth percentile of the data along the specified axis, while ignoring nan values.
[quantile](https://numpy.org/devdocs/reference/generated/numpy.quantile.html#numpy.quantile)(a, q[, axis, out, overwrite_input, …]) | Compute the q-th quantile of the data along the specified axis.
[nanquantile](https://numpy.org/devdocs/reference/generated/numpy.nanquantile.html#numpy.nanquantile)(a, q[, axis, out, …]) | Compute the qth quantile of the data along the specified axis, while ignoring nan values.
## Averages and variances
method | description
---|---
[median](https://numpy.org/devdocs/reference/generated/numpy.median.html#numpy.median)(a[, axis, out, overwrite_input, keepdims]) | Compute the median along the specified axis.
[average](https://numpy.org/devdocs/reference/generated/numpy.average.html#numpy.average)(a[, axis, weights, returned]) | Compute the weighted average along the specified axis.
[mean](https://numpy.org/devdocs/reference/generated/numpy.mean.html#numpy.mean)(a[, axis, dtype, out, keepdims]) | Compute the arithmetic mean along the specified axis.
[std](https://numpy.org/devdocs/reference/generated/numpy.std.html#numpy.std)(a[, axis, dtype, out, ddof, keepdims]) | Compute the standard deviation along the specified axis.
[var](https://numpy.org/devdocs/reference/generated/numpy.var.html#numpy.var)(a[, axis, dtype, out, ddof, keepdims]) | Compute the variance along the specified axis.
[nanmedian](https://numpy.org/devdocs/reference/generated/numpy.nanmedian.html#numpy.nanmedian)(a[, axis, out, overwrite_input, …]) | Compute the median along the specified axis, while ignoring NaNs.
[nanmean](https://numpy.org/devdocs/reference/generated/numpy.nanmean.html#numpy.nanmean)(a[, axis, dtype, out, keepdims]) | Compute the arithmetic mean along the specified axis, ignoring NaNs.
[nanstd](https://numpy.org/devdocs/reference/generated/numpy.nanstd.html#numpy.nanstd)(a[, axis, dtype, out, ddof, keepdims]) | Compute the standard deviation along the specified axis, while ignoring NaNs.
[nanvar](https://numpy.org/devdocs/reference/generated/numpy.nanvar.html#numpy.nanvar)(a[, axis, dtype, out, ddof, keepdims]) | Compute the variance along the specified axis, while ignoring NaNs.
## Correlating
method | description
---|---
[corrcoef](https://numpy.org/devdocs/reference/generated/numpy.corrcoef.html#numpy.corrcoef)(x[, y, rowvar, bias, ddof]) | Return Pearson product-moment correlation coefficients.
[correlate](https://numpy.org/devdocs/reference/generated/numpy.correlate.html#numpy.correlate)(a, v[, mode]) | Cross-correlation of two 1-dimensional sequences.
[cov](https://numpy.org/devdocs/reference/generated/numpy.cov.html#numpy.cov)(m[, y, rowvar, bias, ddof, fweights, …]) | Estimate a covariance matrix, given data and weights.
## Histograms
method | description
---|---
[histogram](https://numpy.org/devdocs/reference/generated/numpy.histogram.html#numpy.histogram)(a[, bins, range, normed, weights, …]) | Compute the histogram of a set of data.
[histogram2d](https://numpy.org/devdocs/reference/generated/numpy.histogram2d.html#numpy.histogram2d)(x, y[, bins, range, normed, …]) | Compute the bi-dimensional histogram of two data samples.
[histogramdd](https://numpy.org/devdocs/reference/generated/numpy.histogramdd.html#numpy.histogramdd)(sample[, bins, range, normed, …]) | Compute the multidimensional histogram of some data.
[bincount](https://numpy.org/devdocs/reference/generated/numpy.bincount.html#numpy.bincount)(x[, weights, minlength]) | Count number of occurrences of each value in array of non-negative ints.
[histogram_bin_edges](https://numpy.org/devdocs/reference/generated/numpy.histogram_bin_edges.html#numpy.histogram_bin_edges)(a[, bins, range, weights]) | Function to calculate only the edges of the bins used by the histogram function.
[digitize](https://numpy.org/devdocs/reference/generated/numpy.digitize.html#numpy.digitize)(x, bins[, right]) | Return the indices of the bins to which each value in input array belongs.

View File

@@ -0,0 +1,35 @@
# 排序,搜索和计数(`Sorting, searching, and counting`)
## 排序(`Sorting`)
method | description
---|---
[sort](https://numpy.org/devdocs/reference/generated/numpy.sort.html#numpy.sort)(a[, axis, kind, order]) | 返回数组的排序副本。
[lexsort](https://numpy.org/devdocs/reference/generated/numpy.lexsort.html#numpy.lexsort)(keys[, axis]) | 使用键的序列执行间接稳定排序。
[argsort](https://numpy.org/devdocs/reference/generated/numpy.argsort.html#numpy.argsort)(a[, axis, kind, order]) | 返回将对数组进行排序的索引。
[ndarray.sort](https://numpy.org/devdocs/reference/generated/numpy.ndarray.sort.html#numpy.ndarray.sort)([axis, kind, order]) | 就地排序数组。
[msort](https://numpy.org/devdocs/reference/generated/numpy.msort.html#numpy.msort)(a) | 返回沿第一个指针排序的数组的副本。
[sort_complex](https://numpy.org/devdocs/reference/generated/numpy.sort_complex.html#numpy.sort_complex)(a) | 首先使用实部,然后使用虚部对复杂数组进行排序。
[partition](https://numpy.org/devdocs/reference/generated/numpy.partition.html#numpy.partition)(a, kth[, axis, kind, order]) | 返回数组的分区副本。
[argpartition](https://numpy.org/devdocs/reference/generated/numpy.argpartition.html#numpy.argpartition)(a, kth[, axis, kind, order]) | 使用kind关键字指定的算法沿给定的指针执行间接分区。
## Searching
method | description
---|---
[argmax](https://numpy.org/devdocs/reference/generated/numpy.argmax.html#numpy.argmax)(a[, axis, out]) | Returns the indices of the maximum values along an axis.
[nanargmax](https://numpy.org/devdocs/reference/generated/numpy.nanargmax.html#numpy.nanargmax)(a[, axis]) | Return the indices of the maximum values in the specified axis ignoring NaNs.
[argmin](https://numpy.org/devdocs/reference/generated/numpy.argmin.html#numpy.argmin)(a[, axis, out]) | Returns the indices of the minimum values along an axis.
[nanargmin](https://numpy.org/devdocs/reference/generated/numpy.nanargmin.html#numpy.nanargmin)(a[, axis]) | Return the indices of the minimum values in the specified axis ignoring NaNs.
[argwhere](https://numpy.org/devdocs/reference/generated/numpy.argwhere.html#numpy.argwhere)(a) | Find the indices of array elements that are non-zero, grouped by element.
[nonzero](https://numpy.org/devdocs/reference/generated/numpy.nonzero.html#numpy.nonzero)(a) | Return the indices of the elements that are non-zero.
[flatnonzero](https://numpy.org/devdocs/reference/generated/numpy.flatnonzero.html#numpy.flatnonzero)(a) | Return indices that are non-zero in the flattened version of a.
[where](https://numpy.org/devdocs/reference/generated/numpy.where.html#numpy.where)(condition, [x, y]) | Return elements chosen from x or y depending on condition.
[searchsorted](https://numpy.org/devdocs/reference/generated/numpy.searchsorted.html#numpy.searchsorted)(a, v[, side, sorter]) | Find indices where elements should be inserted to maintain order.
[extract](https://numpy.org/devdocs/reference/generated/numpy.extract.html#numpy.extract)(condition, arr) | Return the elements of an array that satisfy some condition.
## Counting
method | description
---|---
[count_nonzero](https://numpy.org/devdocs/reference/generated/numpy.count_nonzero.html#numpy.count_nonzero)(a[, axis]) | Counts the number of non-zero values in the array a.

View File

@@ -0,0 +1,32 @@
在几乎所有的机器上,多字节对象都被存储为连续的字节序列。字节顺序,是跨越多字节的程序对象的存储规则。
* 大端模式:指数据的高字节保存在内存的低地址中,而数据的低字节保存在内存的高地址中,这样的存储模式有点儿类似于把数据当作字符串顺序处理:地址由小向大增加,而数据从高位往低位放;这和我们的阅读习惯一致。
* 小端模式:指数据的高字节保存在内存的高地址中,而数据的低字节保存在内存的低地址中,这种存储模式将地址的高低和数据位权有效地结合起来,高地址部分权值高,低地址部分权值低。
## numpy.ndarray.byteswap()
```py
import numpy as np
a = np.array([1, 256, 8755], dtype = np.int16)
print ('我们的数组是:')
print (a)
print ('以十六进制表示内存中的数据:')
print (map(hex,a))
# byteswap() 函数通过传入 true 来原地交换
print ('调用 byteswap() 函数:')
print (a.byteswap(True))
print ('十六进制形式:')
print (map(hex,a))
# 我们可以看到字节已经交换了
输出结果为
我们的数组是
[ 1 256 8755]
以十六进制表示内存中的数据
<map object at 0x104acb400>
调用 byteswap() 函数
[ 256 1 13090]
十六进制形式
<map object at 0x104acb3c8>
```

View File

@@ -0,0 +1,80 @@
# 线性代数(``numpy.linalg``
NumPy线性代数函数依赖于BLAS和LAPACK来提供标准线性代数算法的高效低级实现。
这些库可以由NumPy本身使用其参考实现子集的C版本提供
但如果可能,最好是利用专用处理器功能的高度优化的库。
这样的库的例子是[OpenBLAS](https://www.openblas.net/)、MKL(TM)和ATLAS。因为这些库是多线程和处理器相关的
所以可能需要环境变量和外部包(如[threadpoolctl](https://github.com/joblib/threadpoolctl))来控制线程数量或指定处理器体系结构。
## 矩阵和向量积
方法 | 描述
---|---
[dot](https://numpy.org/devdocs/reference/generated/numpy.dot.html#numpy.dot)(a, b[, out]) | 两个数组的点积。
[linalg.multi_dot](https://numpy.org/devdocs/reference/generated/numpy.linalg.multi_dot.html#numpy.linalg.multi_dot)(arrays) | 在单个函数调用中计算两个或更多数组的点积,同时自动选择最快的求值顺序。
[vdot](https://numpy.org/devdocs/reference/generated/numpy.vdot.html#numpy.vdot)(a, b) | 返回两个向量的点积。
[inner](https://numpy.org/devdocs/reference/generated/numpy.inner.html#numpy.inner)(a, b) | 两个数组的内积。
[outer](https://numpy.org/devdocs/reference/generated/numpy.outer.html#numpy.outer)(a, b[, out]) | 计算两个向量的外积。
[matmul](https://numpy.org/devdocs/reference/generated/numpy.matmul.html#numpy.matmul)(x1, x2, /[, out, casting, order, …]) | 两个数组的矩阵乘积。
[tensordot](https://numpy.org/devdocs/reference/generated/numpy.tensordot.html#numpy.tensordot)(a, b[, axes]) | 沿指定轴计算张量点积。
[einsum](https://numpy.org/devdocs/reference/generated/numpy.einsum.html#numpy.einsum)(subscripts, *operands[, out, dtype, …]) | 计算操作数上的爱因斯坦求和约定。
[einsum_path](https://numpy.org/devdocs/reference/generated/numpy.einsum_path.html#numpy.einsum_path)(subscripts, *operands[, optimize]) | 通过考虑中间数组的创建计算einsum表达式的最低成本压缩顺序。
[linalg.matrix_power](https://numpy.org/devdocs/reference/generated/numpy.linalg.matrix_power.html#numpy.linalg.matrix_power)(a, n) | 将方阵提升为(整数)n次方。
[kron](https://numpy.org/devdocs/reference/generated/numpy.kron.html#numpy.kron)(a, b) | 两个数组的Kronecker乘积。
## 分解
方法 | 描述
---|---
[linalg.cholesky](https://numpy.org/devdocs/reference/generated/numpy.linalg.cholesky.html#numpy.linalg.cholesky)(a) | Cholesky分解
[linalg.qr](https://numpy.org/devdocs/reference/generated/numpy.linalg.qr.html#numpy.linalg.qr)(a[, mode]) | 计算矩阵的QR分解。
[linalg.svd](https://numpy.org/devdocs/reference/generated/numpy.linalg.svd.html#numpy.linalg.svd)(a[, full_matrices, compute_uv, …]) | 奇异值分解
## 矩阵特征值
方法 | 描述
---|---
[linalg.eig](https://numpy.org/devdocs/reference/generated/numpy.linalg.eig.html#numpy.linalg.eig)(a) | 计算方阵的特征值和右特征向量。
[linalg.eigh](https://numpy.org/devdocs/reference/generated/numpy.linalg.eigh.html#numpy.linalg.eigh)(a[, UPLO]) | 返回复数Hermitian共轭对称或实对称矩阵的特征值和特征向量。
[linalg.eigvals](https://numpy.org/devdocs/reference/generated/numpy.linalg.eigvals.html#numpy.linalg.eigvals)(a) | 计算通用矩阵的特征值。
[linalg.eigvalsh](https://numpy.org/devdocs/reference/generated/numpy.linalg.eigvalsh.html#numpy.linalg.eigvalsh)(a[, UPLO]) | 计算复杂的Hermitian或实对称矩阵的特征值。
## 范数和其他数字
方法 | 描述
---|---
[linalg.norm](https://numpy.org/devdocs/reference/generated/numpy.linalg.norm.html#numpy.linalg.norm)(x[, ord, axis, keepdims]) | 矩阵或向量范数。
[linalg.cond](https://numpy.org/devdocs/reference/generated/numpy.linalg.cond.html#numpy.linalg.cond)(x[, p]) | 计算矩阵的条件数。
[linalg.det](https://numpy.org/devdocs/reference/generated/numpy.linalg.det.html#numpy.linalg.det)(a) | 计算数组的行列式。
[linalg.matrix_rank](https://numpy.org/devdocs/reference/generated/numpy.linalg.matrix_rank.html#numpy.linalg.matrix_rank)(M[, tol, hermitian]) | 使用SVD方法返回数组的矩阵的rank
[linalg.slogdet](https://numpy.org/devdocs/reference/generated/numpy.linalg.slogdet.html#numpy.linalg.slogdet)(a) | 计算数组行列式的符号和(自然)对数。
[trace](https://numpy.org/devdocs/reference/generated/numpy.trace.html#numpy.trace)(a[, offset, axis1, axis2, dtype, out]) | 返回数组对角线的和。
## 解方程和逆矩阵
方法 | 描述
---|---
[linalg.solve](https://numpy.org/devdocs/reference/generated/numpy.linalg.solve.html#numpy.linalg.solve)(a, b) | 求解线性矩阵方程或线性标量方程组。
[linalg.tensorsolve](https://numpy.org/devdocs/reference/generated/numpy.linalg.tensorsolve.html#numpy.linalg.tensorsolve)(a, b[, axes]) | 对x求解张量方程a x = b。
[linalg.lstsq](https://numpy.org/devdocs/reference/generated/numpy.linalg.lstsq.html#numpy.linalg.lstsq)(a, b[, rcond]) | 返回线性矩阵方程的最小二乘解。
[linalg.inv](https://numpy.org/devdocs/reference/generated/numpy.linalg.inv.html#numpy.linalg.inv)(a) | 计算矩阵的(乘法)逆。
[linalg.pinv](https://numpy.org/devdocs/reference/generated/numpy.linalg.pinv.html#numpy.linalg.pinv)(a[, rcond, hermitian]) | 计算矩阵的Moore-Penrose伪逆。
[linalg.tensorinv](https://numpy.org/devdocs/reference/generated/numpy.linalg.tensorinv.html#numpy.linalg.tensorinv)(a[, ind]) | 计算N维数组的“逆”。
## 例外
方法 | 描述
---|---
[linalg.LinAlgError](https://numpy.org/devdocs/reference/generated/numpy.linalg.LinAlgError.html#numpy.linalg.LinAlgError) | 泛型Python-linalg函数引发的异常派生对象。
## 一次在多个矩阵上的线性代数
*1.8.0版中的新功能*
上面列出的几个线性代数例程能够一次计算几个矩阵的结果,如果它们堆叠在同一数组中的话。
这在文档中通过输入参数规范(如 ``a : (..., M, M) array_like`` )表示。
这意味着,例如,如果给定输入数组 ``a.shape == (N, M, M)`` 则将其解释为N个矩阵的“堆栈”
每个矩阵的大小为M×M。类似的规范也适用于返回值
例如行列式 ``det : (...)`` 。并且在这种情况下将返回形状 ``det(a).shape == (N,)`` 的数组。
这推广到对高维数组的线性代数操作多维数组的最后1或2维被解释为向量或矩阵视每个操作而定。

76
Python/numpy/16IO.md Normal file
View File

@@ -0,0 +1,76 @@
# 输入和输出
## NumPy二进制文件NPYNPZ
方法 | 描述
---|---
[load](https://numpy.org/devdocs/reference/generated/numpy.load.html#numpy.load)(file[, mmap_mode, allow_pickle, …]) | 从.npy、.npz或pickle文件加载阵列或pickle对象。
[save](https://numpy.org/devdocs/reference/generated/numpy.save.html#numpy.save)(file, arr[, allow_pickle, fix_imports]) | 将数组保存为NumPy.npy格式的二进制文件。
[savez](https://numpy.org/devdocs/reference/generated/numpy.savez.html#numpy.savez)(file, \*args, \*\*kwds) | 将几个数组以未压缩的.npz格式保存到单个文件中。
[savez_compressed](https://numpy.org/devdocs/reference/generated/numpy.savez_compressed.html#numpy.savez_compressed)(file, \*args, \*\*kwds) | 以压缩的.npz格式将几个数组保存到单个文件中。
有关这些二进制文件类型的格式,请参阅
[``numpy.lib.format``](https://numpy.org/devdocs/reference/generated/numpy.lib.format.html#module-numpy.lib.format)
## 文本文件
方法 | 描述
---|---
[loadtxt](https://numpy.org/devdocs/reference/generated/numpy.loadtxt.html#numpy.loadtxt)(fname[, dtype, comments, delimiter, …]) | 从文本文件加载数据。
[savetxt](https://numpy.org/devdocs/reference/generated/numpy.savetxt.html#numpy.savetxt)(fname, X[, fmt, delimiter, newline, …]) | 将数组保存到文本文件。
[genfromtxt](https://numpy.org/devdocs/reference/generated/numpy.genfromtxt.html#numpy.genfromtxt)(fname[, dtype, comments, …]) | 从文本文件加载数据,并按指定方式处理缺少的值。
[fromregex](https://numpy.org/devdocs/reference/generated/numpy.fromregex.html#numpy.fromregex)(file, regexp, dtype[, encoding]) | 使用正则表达式解析从文本文件构造数组。
[fromstring](https://numpy.org/devdocs/reference/generated/numpy.fromstring.html#numpy.fromstring)(string[, dtype, count, sep]) | 从字符串中的文本数据初始化的新一维数组。
[ndarray.tofile](https://numpy.org/devdocs/reference/generated/numpy.ndarray.tofile.html#numpy.ndarray.tofile)(fid[, sep, format]) | 将数组以文本或二进制形式写入文件(默认)。
[ndarray.tolist](https://numpy.org/devdocs/reference/generated/numpy.ndarray.tolist.html#numpy.ndarray.tolist)() | 以Python标量的a.ndim级深嵌套列表的形式返回数组。
## 原始二进制文件
方法 | 描述
---|---
[fromfile](https://numpy.org/devdocs/reference/generated/numpy.fromfile.html#numpy.fromfile)(file[, dtype, count, sep, offset]) | 从文本或二进制文件中的数据构造数组。
[ndarray.tofile](https://numpy.org/devdocs/reference/generated/numpy.ndarray.tofile.html#numpy.ndarray.tofile)(fid[, sep, format]) | 将数组以文本或二进制形式写入文件(默认)。
## 字符串格式
方法 | 描述
---|---
[array2string](https://numpy.org/devdocs/reference/generated/numpy.array2string.html#numpy.array2string)(a[, max_line_width, precision, …]) | 返回数组的字符串表示形式。
[array_repr](https://numpy.org/devdocs/reference/generated/numpy.array_repr.html#numpy.array_repr)(arr[, max_line_width, precision, …]) | 返回数组的字符串表示形式。
[array_str](https://numpy.org/devdocs/reference/generated/numpy.array_str.html#numpy.array_str)(a[, max_line_width, precision, …]) | 返回数组中数据的字符串表示形式。
[format_float_positional](https://numpy.org/devdocs/reference/generated/numpy.format_float_positional.html#numpy.format_float_positional)(x[, precision, …]) | 将浮点标量格式化为位置表示法中的十进制字符串。
[format_float_scientific](https://numpy.org/devdocs/reference/generated/numpy.format_float_scientific.html#numpy.format_float_scientific)(x[, precision, …]) | 将浮点标量格式化为科学记数法中的十进制字符串。
## 内存映射文件
方法 | 描述
---|---
[memmap](https://numpy.org/devdocs/reference/generated/numpy.memmap.html#numpy.memmap) | 创建存储在磁盘上二进制文件中的阵列的内存映射。
## 文本格式选项
方法 | 描述
---|---
[set_printoptions](https://numpy.org/devdocs/reference/generated/numpy.set_printoptions.html#numpy.set_printoptions)([precision, threshold, …]) | 设置打印选项。
[get_printoptions](https://numpy.org/devdocs/reference/generated/numpy.get_printoptions.html#numpy.get_printoptions)() | 返回当前打印选项。
[set_string_function](https://numpy.org/devdocs/reference/generated/numpy.set_string_function.html#numpy.set_string_function)(f[, repr]) | 设置在更好的打印数组时要使用的Python函数。
[printoptions](https://numpy.org/devdocs/reference/generated/numpy.printoptions.html#numpy.printoptions)(\*args, \*\*kwargs) | 上下文管理器,用于设置打印选项。
## 基数n表示
方法 | 描述
---|---
[binary_repr](https://numpy.org/devdocs/reference/generated/numpy.binary_repr.html#numpy.binary_repr)(num[, width]) | 以字符串形式返回输入数字的二进制表示形式。
[base_repr](https://numpy.org/devdocs/reference/generated/numpy.base_repr.html#numpy.base_repr)(number[, base, padding]) | 返回给定基本系统中数字的字符串表示形式。
## 数据源
方法 | 描述
---|---
[DataSource](https://numpy.org/devdocs/reference/generated/numpy.DataSource.html#numpy.DataSource)([destpath]) | 通用数据源文件file、http、ftp等
## 二进制格式描述
方法 | 描述
---|---
[lib.format](https://numpy.org/devdocs/reference/generated/numpy.lib.format.html#module-numpy.lib.format) | 二进制序列化

View File

@@ -0,0 +1,54 @@
# 逻辑函数
## 真值测试
方法 | 描述
---|---
[all](https://numpy.org/devdocs/reference/generated/numpy.all.html#numpy.all)(a[, axis, out, keepdims]) | 测试是否沿给定轴的所有数组元素求值为True。
[any](https://numpy.org/devdocs/reference/generated/numpy.any.html#numpy.any)(a[, axis, out, keepdims]) | 测试沿给定轴的任何数组元素的求值是否为True。
## 数组内容
方法 | 描述
---|---
[isfinite](https://numpy.org/devdocs/reference/generated/numpy.isfinite.html#numpy.isfinite)(x, /[, out, where, casting, order, …]) | 逐一测试有限性(不是无穷大还是不是数字)。
[isinf](https://numpy.org/devdocs/reference/generated/numpy.isinf.html#numpy.isinf)(x, /[, out, where, casting, order, …]) | 逐元素测试正无穷大或负无穷大。
[isnan](https://numpy.org/devdocs/reference/generated/numpy.isnan.html#numpy.isnan)(x, /[, out, where, casting, order, …]) | 对NaN逐个元素进行测试并将结果作为布尔数组返回。
[isnat](https://numpy.org/devdocs/reference/generated/numpy.isnat.html#numpy.isnat)(x, /[, out, where, casting, order, …]) | 对NaT不是时间逐个元素进行测试然后将结果作为布尔数组返回。
[isneginf](https://numpy.org/devdocs/reference/generated/numpy.isneginf.html#numpy.isneginf)(x[, out]) | 逐项测试负无穷大,将结果作为布尔数组返回。
[isposinf](https://numpy.org/devdocs/reference/generated/numpy.isposinf.html#numpy.isposinf)(x[, out]) | 对正无穷大逐个元素进行测试,以布尔数组形式返回结果。
## 数组类型测试
方法 | 描述
---|---
[iscomplex](https://numpy.org/devdocs/reference/generated/numpy.iscomplex.html#numpy.iscomplex)(x) | 返回布尔数组如果输入元素复杂则返回True。
[iscomplexobj](https://numpy.org/devdocs/reference/generated/numpy.iscomplexobj.html#numpy.iscomplexobj)(x) | 检查复杂类型或复杂数字数组。
[isfortran](https://numpy.org/devdocs/reference/generated/numpy.isfortran.html#numpy.isfortran)(a) | 检查数组是否是Fortran连续的而不是C连续的。
[isreal](https://numpy.org/devdocs/reference/generated/numpy.isreal.html#numpy.isreal)(x) | 返回布尔数组如果输入元素为实则返回True。
[isrealobj](https://numpy.org/devdocs/reference/generated/numpy.isrealobj.html#numpy.isrealobj)(x) | 如果x是非复数类型或复数数组则返回True。
[isscalar](https://numpy.org/devdocs/reference/generated/numpy.isscalar.html#numpy.isscalar)(num) | 如果num的类型是标量类型则返回True。
## 逻辑运算
方法 | 描述
---|---
[logical_and](https://numpy.org/devdocs/reference/generated/numpy.logical_and.html#numpy.logical_and)(x1, x2, /[, out, where, …]) | 按元素计算x1和x2的真值。
[logical_or](https://numpy.org/devdocs/reference/generated/numpy.logical_or.html#numpy.logical_or)(x1, x2, /[, out, where, casting, …]) | 按元素计算x1或x2的真值。
[logical_not](https://numpy.org/devdocs/reference/generated/numpy.logical_not.html#numpy.logical_not)(x, /[, out, where, casting, …]) | 计算非x元素的真值。
[logical_xor](https://numpy.org/devdocs/reference/generated/numpy.logical_xor.html#numpy.logical_xor)(x1, x2, /[, out, where, …]) | 按元素计算x1 XOR x2的真值。
## 对照
方法 | 描述
---|---
[allclose](https://numpy.org/devdocs/reference/generated/numpy.allclose.html#numpy.allclose)(a, b[, rtol, atol, equal_nan]) | 如果两个数组在公差范围内按元素方式相等则返回True。
[isclose](https://numpy.org/devdocs/reference/generated/numpy.isclose.html#numpy.isclose)(a, b[, rtol, atol, equal_nan]) | 返回一个布尔数组,其中两个数组在公差范围内按元素方式相等。
[array_equal](https://numpy.org/devdocs/reference/generated/numpy.array_equal.html#numpy.array_equal)(a1, a2) | 如果两个数组具有相同的形状和元素则为True否则为False。
[array_equiv](https://numpy.org/devdocs/reference/generated/numpy.array_equiv.html#numpy.array_equiv)(a1, a2) | 如果输入数组的形状一致且所有元素均相等则返回True。
[greater](https://numpy.org/devdocs/reference/generated/numpy.greater.html#numpy.greater)(x1, x2, /[, out, where, casting, …]) | 按元素返回x1 > x2的真值。
[greater_equal](https://numpy.org/devdocs/reference/generated/numpy.greater_equal.html#numpy.greater_equal)(x1, x2, /[, out, where, …]) | 按元素返回x1 >= x2的真值。
[less](https://numpy.org/devdocs/reference/generated/numpy.less.html#numpy.less)(x1, x2, /[, out, where, casting, …]) | 按元素返回x1 < x2的真值。
[less_equal](https://numpy.org/devdocs/reference/generated/numpy.less_equal.html#numpy.less_equal)(x1, x2, /[, out, where, casting, …]) | 按元素返回x1 =< x2的真值。
[equal](https://numpy.org/devdocs/reference/generated/numpy.equal.html#numpy.equal)(x1, x2, /[, out, where, casting, …]) | 按元素返回x1 == x2
[not_equal](https://numpy.org/devdocs/reference/generated/numpy.not_equal.html#numpy.not_equal)(x1, x2, /[, out, where, casting, …]) | 按元素返回x1 != x2

View File

@@ -0,0 +1,25 @@
# 矩阵库 (``numpy.matlib``)
该模块包含 [``numpy``](index.html#module-numpy) 命名空间中的所有函数, 以下返回 [``矩阵``](https://numpy.org/devdocs/reference/generated/numpy.matrix.html#numpy.matrix) 而不是 [``ndarrays``](https://numpy.org/devdocs/reference/generated/numpy.ndarray.html#numpy.ndarray)的替换函数。
也在numpy命名空间中的函数并返回矩阵
method | description
---|---
[mat](https://numpy.org/devdocs/reference/generated/numpy.mat.html#numpy.mat)(data[, dtype]) | 将输入解释为 [矩阵](https://numpy.org/devdocs/reference/generated/numpy.matrix.html#numpy.matrix).
[matrix](https://numpy.org/devdocs/reference/generated/numpy.matrix.html#numpy.matrix)(data[, dtype, copy]) | 注意:不再建议使用此类,即使对于线性
[asmatrix](https://numpy.org/devdocs/reference/generated/numpy.asmatrix.html#numpy.asmatrix)(data[, dtype]) | 将输入解释为矩阵。
[bmat](https://numpy.org/devdocs/reference/generated/numpy.bmat.html#numpy.bmat)(obj[, ldict, gdict]) | 从字符串,嵌套序列或数组构建矩阵对象。
[``matlib``](#module-numpy.matlib)的替换函数
method | description
---|---
[empty](https://numpy.org/devdocs/reference/generated/numpy.matlib.empty.html#numpy.matlib.empty)(shape[, dtype, order]) | 返回给定形状和类型的新矩阵,而无需初始化条目。
[zeros](https://numpy.org/devdocs/reference/generated/numpy.matlib.zeros.html#numpy.matlib.zeros)(shape[, dtype, order]) | 返回给定形状和类型的矩阵,并用零填充。
[ones](https://numpy.org/devdocs/reference/generated/numpy.matlib.ones.html#numpy.matlib.ones)(shape[, dtype, order]) | 一个矩阵。
[eye](https://numpy.org/devdocs/reference/generated/numpy.matlib.eye.html#numpy.matlib.eye)(n[, M, k, dtype, order]) | 返回一个矩阵,在对角线上有一个,在其他地方为零。
[identity](https://numpy.org/devdocs/reference/generated/numpy.matlib.identity.html#numpy.matlib.identity)(n[, dtype]) | 返回给定大小的平方单位矩阵。
[repmat](https://numpy.org/devdocs/reference/generated/numpy.matlib.repmat.html#numpy.matlib.repmat)(a, m, n) | 重复从0D到2D数组或矩阵MxN次。
[rand](https://numpy.org/devdocs/reference/generated/numpy.matlib.rand.html#numpy.matlib.rand)(\*args) |返回具有给定形状的随机值矩阵。
[randn](https://numpy.org/devdocs/reference/generated/numpy.matlib.randn.html#numpy.matlib.randn)(\*args) | 返回一个随机矩阵,其中包含来自“标准正态”分布的数据。

29
Python/numpy/1概述.md Normal file
View File

@@ -0,0 +1,29 @@
# 量的定义
## 名称
* 标量,单个数据,零阶张量,
* 向量,一维数组,一阶张量,
* 矩阵,二维数组,二阶张量
* 张量,高维数组,张量,
## 关系
* 可以使用向量来定义n维线性空间、n维向量空间。向量以数学的方式描述n维线性空间。标量、向量、矩阵、张量是对n维线性空间的暴力展开。
* 维数数组总共有多少个维度。3维
* 维度:数组每个维度是多少。维度是(2,3,4)
* 范数用来衡量数组的特征。F1范数绝对值之和。F2范数平方和。
* 列表和张量不同。列表的低维的维度可以不同。[[1],[1,2]]。张量,相同维的维度必须一致。
* 对于张量的描述可以使三阶,一阶二维,二阶三维,三阶四维。
* 对于数组的描述应该是三维数组一维维度是2二维维度是3三维维度是4
* 向量描述n维线性空间向量的维度描述线性空间维度的个数向量的数据描述每个维度的大小。
* 高维是外层的,低维是内层的。高维包含多个低维。低维能锁定更精确的数据。高维可以索引低维。
## 运算
* 同维度的四则运算,对应位运算。
* 不同维度的四则运算,进行广播。
* 点乘,同维度,同位置相乘相加。
点乘,不同维度,

View File

@@ -0,0 +1,179 @@
## ndarray对象
* N 维数组对象 ndarray它是一系列同类型数据的集合以 0 下标为开始进行集合中元素的索引。
* ndarray 对象是用于存放同类型元素的多维数组。
* ndarray 中的每个元素在内存中都有相同存储大小的区域。
## ndarray定义
```py
numpy.array(object, dtype = None, copy = True, order = None, subok = False, ndmin = 0)
```
<table class="reference">
<thead>
<tr>
<th style="text-align:left">名称</th>
<th style="text-align:left">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">object</td>
<td style="text-align:left">数组或嵌套的数列</td>
</tr>
<tr>
<td style="text-align:left">dtype</td>
<td style="text-align:left">数组元素的数据类型,可选</td>
</tr>
<tr>
<td style="text-align:left">copy</td>
<td style="text-align:left">对象是否需要复制,可选</td>
</tr>
<tr>
<td style="text-align:left">order</td>
<td style="text-align:left">创建数组的样式C为行方向F为列方向A为任意方向默认</td>
</tr>
<tr>
<td style="text-align:left">subok</td>
<td style="text-align:left">默认返回一个与基类类型一致的数组</td>
</tr>
<tr>
<td style="text-align:left">ndmin</td>
<td style="text-align:left">指定生成数组的最小维度</td>
</tr>
</tbody>
</table>
## ndarray数据类型
<table class="reference">
<thead>
<tr>
<th>名称</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>bool_</td>
<td>布尔型数据类型True 或者 False</td>
</tr>
<tr>
<td>int_</td>
<td>默认的整数类型(类似于 C 语言中的 longint32 或 int64</td>
</tr>
<tr>
<td>intc</td>
<td>与 C 的 int 类型一样,一般是 int32 或 int 64</td>
</tr>
<tr>
<td>intp</td>
<td>用于索引的整数类型(类似于 C 的 ssize_t一般情况下仍然是 int32 或 int64</td>
</tr>
<tr>
<td>int8</td>
<td>字节(-128 to 127</td>
</tr>
<tr>
<td>int16</td>
<td>整数(-32768 to 32767</td>
</tr>
<tr>
<td>int32</td>
<td>整数(-2147483648 to 2147483647</td>
</tr>
<tr>
<td>int64</td>
<td>整数(-9223372036854775808 to 9223372036854775807</td>
</tr>
<tr>
<td>uint8</td>
<td>无符号整数0 to 255</td>
</tr>
<tr>
<td>uint16</td>
<td>无符号整数0 to 65535</td>
</tr>
<tr>
<td>uint32</td>
<td>无符号整数0 to 4294967295</td>
</tr>
<tr>
<td>uint64</td>
<td>无符号整数0 to 18446744073709551615</td>
</tr>
<tr>
<td>float_</td>
<td>float64 类型的简写</td>
</tr>
<tr>
<td>float16</td>
<td>半精度浮点数包括1 个符号位5 个指数位10 个尾数位</td>
</tr>
<tr>
<td>float32</td>
<td>单精度浮点数包括1 个符号位8 个指数位23 个尾数位</td>
</tr>
<tr>
<td>float64</td>
<td>双精度浮点数包括1 个符号位11 个指数位52 个尾数位</td>
</tr>
<tr>
<td>complex_</td>
<td>complex128 类型的简写,即 128 位复数</td>
</tr>
<tr>
<td>complex64</td>
<td>复数,表示双 32 位浮点数(实数部分和虚数部分)</td>
</tr>
<tr>
<td>complex128</td>
<td>复数,表示双 64 位浮点数(实数部分和虚数部分)</td>
</tr>
</tbody>
</table>
## ndarray数据类型操作
方法 | 描述
---|---
[can_cast](https://numpy.org/devdocs/reference/generated/numpy.can_cast.html#numpy.can_cast)(from_, to[, casting]) | 如果根据强制转换规则可以在数据类型之间进行强制转换则返回True。
[promote_types](https://numpy.org/devdocs/reference/generated/numpy.promote_types.html#numpy.promote_types)(type1, type2) | 返回Type1和Type2都可以安全强制转换为的最小大小和最小标量种类的数据类型。
[min_scalar_type](https://numpy.org/devdocs/reference/generated/numpy.min_scalar_type.html#numpy.min_scalar_type)(a) | 对于标量a返回具有最小大小和可以保存其值的最小标量种类的数据类型。
[result_type](https://numpy.org/devdocs/reference/generated/numpy.result_type.html#numpy.result_type)(*arrays_and_dtypes) | 返回将NumPy类型提升规则应用于参数而得到的类型。
[common_type](https://numpy.org/devdocs/reference/generated/numpy.common_type.html#numpy.common_type)(\*arrays) | 返回输入数组通用的标量类型。
[obj2sctype](https://numpy.org/devdocs/reference/generated/numpy.obj2sctype.html#numpy.obj2sctype)(rep[, default]) | 返回对象的Python类型的标量dtype或NumPy等效值。
## 创建数据类型
方法 | 描述
---|---
[dtype](https://numpy.org/devdocs/reference/generated/numpy.dtype.html#numpy.dtype)(obj[, align, copy]) | 创建数据类型对象。
[format_parser](https://numpy.org/devdocs/reference/generated/numpy.format_parser.html#numpy.format_parser)(formats, names, titles[, …]) | 类将格式、名称、标题说明转换为dtype。
## 数据类型信息
方法 | 描述
---|---
[finfo](https://numpy.org/devdocs/reference/generated/numpy.finfo.html#numpy.finfo)(dtype) | 浮点类型的机器限制。
[iinfo](https://numpy.org/devdocs/reference/generated/numpy.iinfo.html#numpy.iinfo)(type) | 整数类型的机器限制。
[MachAr](https://numpy.org/devdocs/reference/generated/numpy.MachAr.html#numpy.MachAr)([float_conv, int_conv, …]) | 诊断机器参数。
## 数据类型测试
方法 | 描述
---|---
[issctype](https://numpy.org/devdocs/reference/generated/numpy.issctype.html#numpy.issctype)(rep) | 确定给定对象是否表示标量数据类型。
[issubdtype](https://numpy.org/devdocs/reference/generated/numpy.issubdtype.html#numpy.issubdtype)(arg1, arg2) | 如果第一个参数是类型层次结构中较低/等于的类型码则返回True。
[issubsctype](https://numpy.org/devdocs/reference/generated/numpy.issubsctype.html#numpy.issubsctype)(arg1, arg2) | 确定第一个参数是否是第二个参数的子类。
[issubclass_](https://numpy.org/devdocs/reference/generated/numpy.issubclass_.html#numpy.issubclass_)(arg1, arg2) | 确定一个类是否是第二个类的子类。
[find_common_type](https://numpy.org/devdocs/reference/generated/numpy.find_common_type.html#numpy.find_common_type)(array_types, scalar_types) | 按照标准强制规则确定常见类型。
## 杂项
方法 | 描述
---|---
[typename](https://numpy.org/devdocs/reference/generated/numpy.typename.html#numpy.typename)(char) | 返回给定数据类型代码的说明。
[sctype2char](https://numpy.org/devdocs/reference/generated/numpy.sctype2char.html#numpy.sctype2char)(sctype) | 返回标量dtype的字符串表示形式。
[mintypecode](https://numpy.org/devdocs/reference/generated/numpy.mintypecode.html#numpy.mintypecode)(typechars[, typeset, default]) | 返回给定类型可以安全强制转换到的最小大小类型的字符。
[maximum_sctype](https://numpy.org/devdocs/reference/generated/numpy.maximum_sctype.html#numpy.maximum_sctype)(t) | 返回与输入类型相同精度最高的标量类型。

View File

@@ -0,0 +1,57 @@
## 基本概念
NumPy 数组的维数称为秩rank秩就是轴的数量即数组的维数一维数组的秩为 1二维数组的秩为 2以此类推。
很多时候可以声明 axis。axis=0表示沿着第 0 轴进行操作即对每一列进行操作axis=1表示沿着第1轴进行操作即对每一行进行操作。
* 轴=秩=维数
* 第一维是高维,最后一维是低维。
## 数组属性
<table class="reference">
<thead>
<tr class="header">
<th>属性</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>ndarray.ndim</td>
<td>秩,即轴的数量或维度的数量</td>
</tr>
<tr>
<td>ndarray.shape</td>
<td>数组的维度对于矩阵n 行 m 列</td>
</tr>
<tr>
<td>ndarray.size</td>
<td>数组元素的总个数,相当于 .shape 中 n*m 的值</td>
</tr>
<tr>
<td>ndarray.dtype</td>
<td>ndarray 对象的元素类型</td>
</tr>
<tr>
<td>ndarray.itemsize</td>
<td>ndarray 对象中每个元素的大小,以字节为单位</td>
</tr>
<tr>
<td>ndarray.flags</td>
<td>ndarray 对象的内存信息</td>
</tr>
<tr>
<td>ndarray.real</td>
<td>ndarray元素的实部</td>
</tr>
<tr>
<td>ndarray.imag</td>
<td>ndarray 元素的虚部</td>
</tr>
<tr>
<td>ndarray.data</td>
<td>包含实际数组元素的缓冲区,由于一般通过数组的索引获取元素,所以通常不需要使用这个属性。</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,85 @@
## 填充创建
方法 | 描述
---|---
[empty](https://numpy.org/devdocs/reference/generated/numpy.empty.html#numpy.empty)(shape[, dtype, order]) | 返回给定形状和类型的新数组,而无需初始化条目。
[empty_like](https://numpy.org/devdocs/reference/generated/numpy.empty_like.html#numpy.empty_like)(prototype[, dtype, order, subok, …]) | 返回形状和类型与给定数组相同的新数组。
[eye](https://numpy.org/devdocs/reference/generated/numpy.eye.html#numpy.eye)(N[, M, k, dtype, order]) | 返回一个二维数组,对角线上有一个,其他地方为零。
[identity](https://numpy.org/devdocs/reference/generated/numpy.identity.html#numpy.identity)(n[, dtype]) | 返回标识数组。
[ones](https://numpy.org/devdocs/reference/generated/numpy.ones.html#numpy.ones)(shape[, dtype, order]) | 返回给定形状和类型的新数组并填充为1。
[ones_like](https://numpy.org/devdocs/reference/generated/numpy.ones_like.html#numpy.ones_like)(a[, dtype, order, subok, shape]) | 返回形状与类型与给定数组相同的数组。
[zeros](https://numpy.org/devdocs/reference/generated/numpy.zeros.html#numpy.zeros)(shape[, dtype, order]) | 返回给定形状和类型的新数组,并用零填充。
[zeros_like](https://numpy.org/devdocs/reference/generated/numpy.zeros_like.html#numpy.zeros_like)(a[, dtype, order, subok, shape]) | 返回形状与类型与给定数组相同的零数组。
[full](https://numpy.org/devdocs/reference/generated/numpy.full.html#numpy.full)(shape, fill_value[, dtype, order]) | 返回给定形状和类型的新数组并用fill_value填充。
[full_like](https://numpy.org/devdocs/reference/generated/numpy.full_like.html#numpy.full_like)(a, fill_value[, dtype, order, …]) | 返回形状和类型与给定数组相同的完整数组。
## 从现有数据创建
方法 | 描述
---|---
[array](https://numpy.org/devdocs/reference/generated/numpy.array.html#numpy.array)(object[, dtype, copy, order, subok, ndmin]) | 创建一个数组。
[asarray](https://numpy.org/devdocs/reference/generated/numpy.asarray.html#numpy.asarray)(a[, dtype, order]) | 将输入转换为数组。
[asanyarray](https://numpy.org/devdocs/reference/generated/numpy.asanyarray.html#numpy.asanyarray)(a[, dtype, order]) | 将输入转换为ndarray但通过ndarray子类。
[ascontiguousarray](https://numpy.org/devdocs/reference/generated/numpy.ascontiguousarray.html#numpy.ascontiguousarray)(a[, dtype]) | 返回内存中的连续数组ndim > = 1C顺序
[asmatrix](https://numpy.org/devdocs/reference/generated/numpy.asmatrix.html#numpy.asmatrix)(data[, dtype]) | 将输入解释为矩阵。
[copy](https://numpy.org/devdocs/reference/generated/numpy.copy.html#numpy.copy)(a[, order]) | 返回给定对象的数组副本。
[frombuffer](https://numpy.org/devdocs/reference/generated/numpy.frombuffer.html#numpy.frombuffer)(buffer[, dtype, count, offset]) | 将缓冲区解释为一维数组。
[fromfile](https://numpy.org/devdocs/reference/generated/numpy.fromfile.html#numpy.fromfile)(file[, dtype, count, sep, offset]) | 根据文本或二进制文件中的数据构造一个数组。
[fromfunction](https://numpy.org/devdocs/reference/generated/numpy.fromfunction.html#numpy.fromfunction)(function, shape, \*\*kwargs) | 通过在每个坐标上执行一个函数来构造一个数组。
[fromiter](https://numpy.org/devdocs/reference/generated/numpy.fromiter.html#numpy.fromiter)(iterable, dtype[, count]) | 从可迭代对象创建一个新的一维数组。
[fromstring](https://numpy.org/devdocs/reference/generated/numpy.fromstring.html#numpy.fromstring)(string[, dtype, count, sep]) | 从字符串中的文本数据初始化的新一维数组。
[loadtxt](https://numpy.org/devdocs/reference/generated/numpy.loadtxt.html#numpy.loadtxt)(fname[, dtype, comments, delimiter, …]) | 从文本文件加载数据。
## 创建记录的数组
方法 | 描述
---|---
[core.records.array](https://numpy.org/devdocs/reference/generated/numpy.core.records.array.html#numpy.core.records.array)(obj[, dtype, shape, …]) | 从各种各样的对象构造一个记录数组。
[core.records.fromarrays](https://numpy.org/devdocs/reference/generated/numpy.core.records.fromarrays.html#numpy.core.records.fromarrays)(arrayList[, dtype, …]) | 从(平面)数组列表创建记录数组
[core.records.fromrecords](https://numpy.org/devdocs/reference/generated/numpy.core.records.fromrecords.html#numpy.core.records.fromrecords)(recList[, dtype, …]) | 从文本格式的记录列表创建一个rearray
[core.records.fromstring](https://numpy.org/devdocs/reference/generated/numpy.core.records.fromstring.html#numpy.core.records.fromstring)(datastring[, dtype, …]) | 根据字符串中包含的二进制数据创建(只读)记录数组
[core.records.fromfile](https://numpy.org/devdocs/reference/generated/numpy.core.records.fromfile.html#numpy.core.records.fromfile)(fd[, dtype, shape, …]) | 根据二进制文件数据创建数组
## 创建字符数组
方法 | 描述
---|---
[core.defchararray.array](https://numpy.org/devdocs/reference/generated/numpy.core.defchararray.array.html#numpy.core.defchararray.array)(obj[, itemsize, …]) | 创建一个chararray。
[core.defchararray.asarray](https://numpy.org/devdocs/reference/generated/numpy.core.defchararray.asarray.html#numpy.core.defchararray.asarray)(obj[, itemsize, …]) | 将输入转换为chararray仅在必要时复制数据。
## 数值范围
方法 | 描述
---|---
[arange](https://numpy.org/devdocs/reference/generated/numpy.arange.html#numpy.arange)([start,] stop[, step,][, dtype]) | 返回给定间隔内的均匀间隔的值。
[np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)](https://numpy.org/devdocs/reference/generated/numpy.linspace.html#numpy.linspace) | 返回指定间隔内的等间隔数字。
[logspace](https://numpy.org/devdocs/reference/generated/numpy.logspace.html#numpy.logspace)(start, stop[, num, endpoint, base, …]) | 返回数以对数刻度均匀分布。
[geomspace](https://numpy.org/devdocs/reference/generated/numpy.geomspace.html#numpy.geomspace)(start, stop[, num, endpoint, …]) | 返回数字以对数刻度(几何级数)均匀分布。
[meshgrid](https://numpy.org/devdocs/reference/generated/numpy.meshgrid.html#numpy.meshgrid)(\*xi, \*\*kwargs) | 从坐标向量返回坐标矩阵。
[mgrid](https://numpy.org/devdocs/reference/generated/numpy.mgrid.html#numpy.mgrid) | nd_grid实例它返回一个密集的多维“ meshgrid”。
[ogrid](https://numpy.org/devdocs/reference/generated/numpy.ogrid.html#numpy.ogrid) | nd_grid实例它返回一个开放的多维“ meshgrid”。
## 创建矩阵
方法 | 描述
---|---
[diag](https://numpy.org/devdocs/reference/generated/numpy.diag.html#numpy.diag)(v[, k]) | 提取对角线或构造对角线数组。
[diagflat](https://numpy.org/devdocs/reference/generated/numpy.diagflat.html#numpy.diagflat)(v[, k]) | 使用展平的输入作为对角线创建二维数组。
[tri](https://numpy.org/devdocs/reference/generated/numpy.tri.html#numpy.tri)(N[, M, k, dtype]) | 在给定对角线处及以下且在其他位置为零的数组。
[tril](https://numpy.org/devdocs/reference/generated/numpy.tril.html#numpy.tril)(m[, k]) | 数组的下三角。
[triu](https://numpy.org/devdocs/reference/generated/numpy.triu.html#numpy.triu)(m[, k]) | 数组的上三角。
[vander](https://numpy.org/devdocs/reference/generated/numpy.vander.html#numpy.vander)(x[, N, increasing]) | 生成范德蒙矩阵。
## 定义矩阵
方法 | 描述
---|---
[mat](https://numpy.org/devdocs/reference/generated/numpy.mat.html#numpy.mat)(data[, dtype]) | 将输入解释为矩阵。
[bmat](https://numpy.org/devdocs/reference/generated/numpy.bmat.html#numpy.bmat)(obj[, ldict, gdict]) | 从字符串,嵌套序列或数组构建矩阵对象。

View File

@@ -0,0 +1,296 @@
# 索引
* 有三种可用的索引方法类型: 字段访问,基本切片和高级索引
* 所有的索引方式都是在方括号内。
* :表示切片
* ,表示高维度索引
* [][]表示递归索引,对索引结果再次索引。
## 字段访问
ndarray对象的内容可以通过索引或切片来访问和修改与 Python 中 list 的切片操作一样。
ndarray 数组可以基于 0 - n 的下标进行索引。
```py
import numpy as np
a = np.arange(10)
s = slice(2,7,2) # 从索引 2 开始到索引 7 停止间隔为2
print (a[s])
```
## 基本切片
切片对象可以通过内置的 slice 函数,并设置 start, stop 及 step 参数进行,从原数组中切割出一个新数组。
* 基本切片语法是 i:j:k其中 i 是起始索引j 是停止索引k 是步骤k\neq0。这将选择具有索引值在相应的维度中i, i+k, ..., i+(m-1) k 的 m 个元素,
```py
import numpy as np
a = np.arange(10)
b = a[2:7:2] # 从索引 2 开始到索引 7 停止,间隔为 2
print(b)
```
* 负 i 和 j 被解释为 n + i 和 n + j ,其中 n 是相应维度中的元素数量。负 k 使得踩踏指向更小的指数。
```py
>>> x[-2:10]
array([8, 9])
>>> x[-3:3:-1]
array([7, 6, 5, 4])
```
* 切片还可以包括省略号 …,来使选择元组的长度与数组的维度相同。 如果在行位置使用省略号,它将返回包含行中元素的 ndarray。Ellipsis扩展:为选择元组索引所有维度所需的对象数。在大多数情况下这意味着扩展选择元组的长度是x.ndim。可能只存在一个省略号。
```py
import numpy as np
a = np.array([[1,2,3],[3,4,5],[4,5,6]])
print (a[...,1]) # 第2列元素
print (a[1,...]) # 第2行元素
print (a[...,1:]) # 第2列及剩下的所有元素
```
## 高级索引
数组可以由整数数组索引、布尔索引及花式索引。
### 整数数组索引
当索引包含尽可能多的整数数组时,索引的数组具有维度,索引是直接的,但与切片不同。
* 高级索引始终作为 一个 整体进行 广播 和迭代:
```py
result[i_1, ..., i_M] == x[ind_1[i_1, ..., i_M], ind_2[i_1, ..., i_M],..., ind_N[i_1, ..., i_M]]
```
* 应从每一行中选择特定的元素。 行索引只是[012],列索引指定要为相应行选择的元素,这里是[010]。 将两者结合使用,可以使用高级索引解决任务
```py
import numpy as np
x = np.array([[1, 2], [3, 4], [5, 6]])
y = x[[0,1,2], [0,1,0]]
print (y)
>>> [1,4,5]
```
### 布尔索引
我们可以通过一个布尔数组来索引目标数组。
布尔索引通过布尔运算(如:比较运算符)来获取符合指定条件的元素的数组。
```py
import numpy as np
x = np.array([[ 0, 1, 2],[ 3, 4, 5],[ 6, 7, 8],[ 9, 10, 11]])
print ('我们的数组是:')
print (x)
print ('\n')
# 现在我们会打印出大于 5 的元素
print ('大于 5 的元素是:')
print (x[x > 5])
我们的数组是
[[ 0 1 2]
[ 3 4 5]
[ 6 7 8]
[ 9 10 11]]
大于 5 的元素是
[ 6 7 8 9 10 11]
```
### 花式索引
花式索引指的是利用整数数组进行索引。
* 花式索引根据索引数组的值作为目标数组的某个轴的下标来取值。对于使用一维整型数组作为索引,如果目标是一维数组,那么索引的结果就是对应位置的元素;如果目标是二维数组,那么就是对应下标的行。花式索引跟切片不一样,它总是将数据复制到新数组中。
* 传入顺序索引数组
```py
import numpy as np
x=np.arange(32).reshape((8,4))
print (x[[4,2,1,7]])
输出结果为
[[16 17 18 19]
[ 8 9 10 11]
[ 4 5 6 7]
[28 29 30 31]]
```
* 传入倒序索引数组
```
import numpy as np
x=np.arange(32).reshape((8,4))
print (x[[-4,-2,-1,-7]])
输出结果为:
[[16 17 18 19]
[24 25 26 27]
[28 29 30 31]
[ 4 5 6 7]]
```
# 迭代数组
## 迭代器
NumPy 迭代器对象 numpy.nditer 提供了一种灵活访问一个或者多个数组元素的方式。
```py
import numpy as np
a = np.arange(6).reshape(2,3)
print ('原始数组是:')
print (a)
print ('\n')
print ('迭代输出元素:')
for x in np.nditer(a):
print (x, end=", " )
print ('\n')
```
## 按顺序迭代
这反映了默认情况下只需访问每个元素,而无需考虑其特定顺序。我们可以通过迭代上述数组的转置来看到这一点,并与以 C 顺序访问数组转置的 copy 方式做对比,如下实例:
```py
import numpy as np
a = np.arange(6).reshape(2,3)
for x in np.nditer(a.T):
print (x, end=", " )
print ('\n')
for x in np.nditer(a.T.copy(order='C')):
print (x, end=", " )
print ('\n')
```
控制遍历顺序
`for x in np.nditer(a, order='F'):Fortran order`,即是列序优先;
`for x in np.nditer(a.T, order='C'):C order`,即是行序优先
```py
import numpy as np
a = np.arange(0,60,5)
a = a.reshape(3,4)
print ('原始数组是:')
print (a)
print ('\n')
print ('原始数组的转置是:')
b = a.T
print (b)
print ('\n')
print ('以 C 风格顺序排序:')
c = b.copy(order='C')
print (c)
for x in np.nditer(c):
print (x, end=", " )
print ('\n')
print ('以 F 风格顺序排序:')
c = b.copy(order='F')
print (c)
for x in np.nditer(c):
print (x, end=", " )
输出结果为
原始数组是
[[ 0 5 10 15]
[20 25 30 35]
[40 45 50 55]]
原始数组的转置是
[[ 0 20 40]
[ 5 25 45]
[10 30 50]
[15 35 55]]
C 风格顺序排序
[[ 0 20 40]
[ 5 25 45]
[10 30 50]
[15 35 55]]
0, 20, 40, 5, 25, 45, 10, 30, 50, 15, 35, 55,
F 风格顺序排序
[[ 0 20 40]
[ 5 25 45]
[10 30 50]
[15 35 55]]
0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55,
```
## 修改迭代的值
修改数组中元素的值
nditer 对象有另一个可选参数 op_flags。 默认情况下nditer 将视待迭代遍历的数组为只读对象read-only为了在遍历数组的同时实现对数组元素值得修改必须指定 read-write 或者 write-only 的模式。
```py
import numpy as np
a = np.arange(0,60,5)
a = a.reshape(3,4)
print ('原始数组是:')
print (a)
print ('\n')
for x in np.nditer(a, op_flags=['readwrite']):
x[...]=2*x
print ('修改后的数组是:')
print (a)
输出结果为
原始数组是
[[ 0 5 10 15]
[20 25 30 35]
[40 45 50 55]]
修改后的数组是
[[ 0 10 20 30]
[ 40 50 60 70]
[ 80 90 100 110]]
```
## 广播迭代
广播迭代
如果两个数组是可广播的nditer 组合对象能够同时迭代它们。 假设数组 a 的维度为 3X4数组 b 的维度为 1X4 ,则使用以下迭代器(数组 b 被广播到 a 的大小)。
```py
import numpy as np
a = np.arange(0,60,5)
a = a.reshape(3,4)
print ('第一个数组为:')
print (a)
print ('\n')
print ('第二个数组为:')
b = np.array([1, 2, 3, 4], dtype = int)
print (b)
print ('\n')
print ('修改后的数组为:')
for x,y in np.nditer([a,b]):
print ("%d:%d" % (x,y), end=", " )
输出结果为
第一个数组为
[[ 0 5 10 15]
[20 25 30 35]
[40 45 50 55]]
第二个数组为
[1 2 3 4]
修改后的数组为
0:1, 5:2, 10:3, 15:4, 20:1, 25:2, 30:3, 35:4, 40:1, 45:2, 50:3, 55:4,
```

View File

@@ -0,0 +1,57 @@
## 广播
广播(Broadcast)是 numpy 对不同形状(shape)的数组进行数值计算的方式, 对数组的算术运算通常在相应的元素上进行。
低纬度向高维度广播。低纬度在高维度方向上复制。
```py
import numpy as np
a = np.array([[ 0, 0, 0],
[10,10,10],
[20,20,20],
[30,30,30]])
b = np.array([1,2,3])
bb = np.tile(b, (4, 1)) # 重复 b 的各个维度
print(a + bb)
输出结果为
[[ 1 2 3]
[11 12 13]
[21 22 23]
[31 32 33]]
```
## 广播原则
广播的规则:
* 让所有输入数组都向其中形状最长的数组看齐,形状中不足的部分都通过在前面加 1 补齐。
* 输出数组的形状是输入数组形状的各个维度上的最大值。
* 如果输入数组的某个维度和输出数组的对应维度的长度相同或者其长度为 1 时,这个数组能够用来计算,否则出错。
* 当输入数组的某个维度的长度为 1 时,沿着此维度运算时都用此维度上的第一组值。
## 主动广播
```py
numpy.broadcast
broadcast_arrays
broadcast_to
```
Manually adding two vectors, using broadcasting:
```py
x = np.array([[1], [2], [3]])
y = np.array([4, 5, 6])
b = np.broadcast(x, y)
out = np.empty(b.shape)
out.flat = [u+v for (u,v) in b]
out
array([[5., 6., 7.],
[6., 7., 8.],
[7., 8., 9.]])
Compare against built-in broadcasting:
x + y
array([[5, 6, 7],
[6, 7, 8],
[7, 8, 9]])
```

View File

@@ -0,0 +1,106 @@
# 数组处理程序
> 主要对数组本身的进行更改。并不是进行运算。
## 复制数组
方法 | 描述
---|---
[copyto](https://numpy.org/devdocs/reference/generated/numpy.copyto.html#numpy.copyto)(dst, src[, casting, where]) | 将值从一个数组复制到另一个数组,并根据需要进行广播。
## 改变形状
方法 | 描述
---|---
[reshape](https://numpy.org/devdocs/reference/generated/numpy.reshape.html#numpy.reshape)(a, newshape[, order]) | 在不更改数据的情况下为数组赋予新的形状。
[ravel](https://numpy.org/devdocs/reference/generated/numpy.ravel.html#numpy.ravel)(a[, order]) | 返回一个连续的扁平数组。
[ndarray.flat](https://numpy.org/devdocs/reference/generated/numpy.ndarray.flat.html#numpy.ndarray.flat) | 数组上的一维迭代器。
[ndarray.flatten](https://numpy.org/devdocs/reference/generated/numpy.ndarray.flatten.html#numpy.ndarray.flatten)([order]) | 返回折叠成一维的数组副本。
## 转置数组
方法 | 描述
---|---
[moveaxis](https://numpy.org/devdocs/reference/generated/numpy.moveaxis.html#numpy.moveaxis)(a, source, destination) | 将数组的轴移到新位置。
[rollaxis](https://numpy.org/devdocs/reference/generated/numpy.rollaxis.html#numpy.rollaxis)(a, axis[, start]) | 向后滚动指定的轴,直到其位于给定的位置。
[swapaxes](https://numpy.org/devdocs/reference/generated/numpy.swapaxes.html#numpy.swapaxes)(a, axis1, axis2) | 互换数组的两个轴。
[ndarray.T](https://numpy.org/devdocs/reference/generated/numpy.ndarray.T.html#numpy.ndarray.T) | 转置数组。
[transpose](https://numpy.org/devdocs/reference/generated/numpy.transpose.html#numpy.transpose)(a[, axes]) | 排列数组的尺寸。
## 更改维度数
方法 | 描述
---|---
[atleast_1d](https://numpy.org/devdocs/reference/generated/numpy.atleast_1d.html#numpy.atleast_1d)(\*arys) | 将输入转换为至少一维的数组。
[atleast_2d](https://numpy.org/devdocs/reference/generated/numpy.atleast_2d.html#numpy.atleast_2d)(\*arys) | 将输入视为至少具有二维的数组。
[atleast_3d](https://numpy.org/devdocs/reference/generated/numpy.atleast_3d.html#numpy.atleast_3d)(\*arys) | 以至少三个维度的数组形式查看输入。
[broadcast](https://numpy.org/devdocs/reference/generated/numpy.broadcast.html#numpy.broadcast) | 产生模仿广播的对象。
[broadcast_to](https://numpy.org/devdocs/reference/generated/numpy.broadcast_to.html#numpy.broadcast_to)(array, shape[, subok]) | 将数组广播为新形状。
[broadcast_arrays](https://numpy.org/devdocs/reference/generated/numpy.broadcast_arrays.html#numpy.broadcast_arrays)(\*args, \*\*kwargs) | 互相广播任意数量的阵列。
[expand_dims](https://numpy.org/devdocs/reference/generated/numpy.expand_dims.html#numpy.expand_dims)(a, axis) | 扩展数组的形状。
[squeeze](https://numpy.org/devdocs/reference/generated/numpy.squeeze.html#numpy.squeeze)(a[, axis]) | 从数组形状中删除一维条目。
## 改变数组的种类
方法 | 描述
---|---
[asarray](https://numpy.org/devdocs/reference/generated/numpy.asarray.html#numpy.asarray)(a[, dtype, order]) | 将输入转换为数组。
[asanyarray](https://numpy.org/devdocs/reference/generated/numpy.asanyarray.html#numpy.asanyarray)(a[, dtype, order]) | 将输入转换为ndarray但通过ndarray子类。
[asmatrix](https://numpy.org/devdocs/reference/generated/numpy.asmatrix.html#numpy.asmatrix)(data[, dtype]) | 将输入解释为矩阵。
[asfarray](https://numpy.org/devdocs/reference/generated/numpy.asfarray.html#numpy.asfarray)(a[, dtype]) | 返回转换为浮点类型的数组。
[asfortranarray](https://numpy.org/devdocs/reference/generated/numpy.asfortranarray.html#numpy.asfortranarray)(a[, dtype]) | 返回以Fortran顺序排列在内存中的数组ndim> = 1
[ascontiguousarray](https://numpy.org/devdocs/reference/generated/numpy.ascontiguousarray.html#numpy.ascontiguousarray)(a[, dtype]) | 返回内存中的连续数组ndim> = 1C顺序
[asarray_chkfinite](https://numpy.org/devdocs/reference/generated/numpy.asarray_chkfinite.html#numpy.asarray_chkfinite)(a[, dtype, order]) | 将输入转换为数组检查NaN或Infs。
[asscalar](https://numpy.org/devdocs/reference/generated/numpy.asscalar.html#numpy.asscalar)(a) | 将大小为1的数组转换为其等效的标量。
[require](https://numpy.org/devdocs/reference/generated/numpy.require.html#numpy.require)(a[, dtype, requirements]) | 返回提供的类型满足要求的ndarray。
## 组合数组
方法 | 描述
---|---
[concatenate](https://numpy.org/devdocs/reference/generated/numpy.concatenate.html#numpy.concatenate)((a1, a2, …) | 沿现有轴连接一系列数组。
[stack](https://numpy.org/devdocs/reference/generated/numpy.stack.html#numpy.stack)(arrays[, axis, out]) | 沿新轴连接一系列数组。
[column_stack](https://numpy.org/devdocs/reference/generated/numpy.column_stack.html#numpy.column_stack)(tup) | 将一维数组作为列堆叠到二维数组中。
[dstack](https://numpy.org/devdocs/reference/generated/numpy.dstack.html#numpy.dstack)(tup) | 沿深度方向(沿第三轴)按顺序堆叠数组。
[hstack](https://numpy.org/devdocs/reference/generated/numpy.hstack.html#numpy.hstack)(tup) | 水平(按列)顺序堆叠数组。
[vstack](https://numpy.org/devdocs/reference/generated/numpy.vstack.html#numpy.vstack)(tup) | 垂直(行)按顺序堆叠数组。
[block](https://numpy.org/devdocs/reference/generated/numpy.block.html#numpy.block)(arrays) | 从块的嵌套列表中组装一个nd数组。
## 拆分数组
方法 | 描述
---|---
[split](https://numpy.org/devdocs/reference/generated/numpy.split.html#numpy.split)(ary, indices_or_sections[, axis]) | 将数组拆分为多个子数组作为ary的视图。
[array_split](https://numpy.org/devdocs/reference/generated/numpy.array_split.html#numpy.array_split)(ary, indices_or_sections[, axis]) | 将一个数组拆分为多个子数组。
[dsplit](https://numpy.org/devdocs/reference/generated/numpy.dsplit.html#numpy.dsplit)(ary, indices_or_sections) | 沿第3轴深度将数组拆分为多个子数组。
[hsplit](https://numpy.org/devdocs/reference/generated/numpy.hsplit.html#numpy.hsplit)(ary, indices_or_sections) | 水平(按列)将一个数组拆分为多个子数组。
[vsplit](https://numpy.org/devdocs/reference/generated/numpy.vsplit.html#numpy.vsplit)(ary, indices_or_sections) | 垂直(行)将数组拆分为多个子数组。
## 平铺数组
方法 | 描述
---|---
[tile](https://numpy.org/devdocs/reference/generated/numpy.tile.html#numpy.tile)(A, reps) | 通过重复A代表次数来构造一个数组。
[repeat](https://numpy.org/devdocs/reference/generated/numpy.repeat.html#numpy.repeat)(a, repeats[, axis]) | 重复数组的元素。
## 添加和删除元素
方法 | 描述
---|---
[delete](https://numpy.org/devdocs/reference/generated/numpy.delete.html#numpy.delete)(arr, obj[, axis]) | 返回一个新的数组,该数组具有沿删除的轴的子数组。
[insert](https://numpy.org/devdocs/reference/generated/numpy.insert.html#numpy.insert)(arr, obj, values[, axis]) | 沿给定轴在给定索引之前插入值。
[append](https://numpy.org/devdocs/reference/generated/numpy.append.html#numpy.append)(arr, values[, axis]) | 将值附加到数组的末尾。
[resize](https://numpy.org/devdocs/reference/generated/numpy.resize.html#numpy.resize)(a, new_shape) | 返回具有指定形状的新数组。
[trim_zeros](https://numpy.org/devdocs/reference/generated/numpy.trim_zeros.html#numpy.trim_zeros)s(filt[, trim]) | 修剪一维数组或序列中的前导和/或尾随零。
[unique](https://numpy.org/devdocs/reference/generated/numpy.unique.html#numpy.unique)(ar[, return_index, return_inverse, …]) | 查找数组的唯一元素。
## 重新排列元素
方法 | 描述
---|---
[flip](https://numpy.org/devdocs/reference/generated/numpy.flip.html#numpy.flip)(m[, axis]) | 沿给定轴颠倒数组中元素的顺序。
[fliplr](https://numpy.org/devdocs/reference/generated/numpy.fliplr.html#numpy.fliplr)(m) | 左右翻转数组。
[flipud](https://numpy.org/devdocs/reference/generated/numpy.flipud.html#numpy.flipud)(m) | 上下翻转阵列。
[reshape](https://numpy.org/devdocs/reference/generated/numpy.reshape.html#numpy.reshape)(a, newshape[, order]) | 在不更改数据的情况下为数组赋予新的形状。
[roll](https://numpy.org/devdocs/reference/generated/numpy.roll.html#numpy.roll)(a, shift[, axis]) | 沿给定轴滚动数组元素。
[rot90](https://numpy.org/devdocs/reference/generated/numpy.rot90.html#numpy.rot90)(m[, k, axes]) | 在轴指定的平面中将阵列旋转90度。

View File

@@ -0,0 +1,25 @@
# 二进制运算
## 逐元素位操作
方法 | 描述
---|---
[bitwise_and](https://numpy.org/devdocs/reference/generated/numpy.bitwise_and.html#numpy.bitwise_and)(x1, x2, /[, out, where, …]) | 按元素计算两个数组的按位与。
[bitwise_or](https://numpy.org/devdocs/reference/generated/numpy.bitwise_or.html#numpy.bitwise_or)(x1, x2, /[, out, where, casting, …]) | 按元素计算两个数组的按位或。
[bitwise_xor](https://numpy.org/devdocs/reference/generated/numpy.bitwise_xor.html#numpy.bitwise_xor)(x1, x2, /[, out, where, …]) | 按元素计算两个数组的按位XOR。
[invert](https://numpy.org/devdocs/reference/generated/numpy.invert.html#numpy.invert)(x, /[, out, where, casting, order, …]) | 按元素计算按位求逆,或按位求非。
[left_shift](https://numpy.org/devdocs/reference/generated/numpy.left_shift.html#numpy.left_shift)(x1, x2, /[, out, where, casting, …]) | 将整数的位向左移动。
[right_shift](https://numpy.org/devdocs/reference/generated/numpy.right_shift.html#numpy.right_shift)(x1, x2, /[, out, where, …]) | 向右移整数的位。
## 打包二进制
方法 | 描述
---|---
[packbits](https://numpy.org/devdocs/reference/generated/numpy.packbits.html#numpy.packbits)(a[, axis, bitorder]) | 将二进制值数组的元素打包为uint8数组中的位。
[unpackbits](https://numpy.org/devdocs/reference/generated/numpy.unpackbits.html#numpy.unpackbits)(a[, axis, count, bitorder]) | 将uint8数组的元素解压缩为二进制值输出数组。
## 输出格式
方法 | 描述
---|---
[binary_repr](https://numpy.org/devdocs/reference/generated/numpy.binary_repr.html#numpy.binary_repr)(num[, width]) | 以字符串形式返回输入数字的二进制表示形式。

View File

@@ -0,0 +1,79 @@
# 字符串操作
``numpy.char`` 模块为类型 ``numpy.string_`` 或的数组提供了一组向量化的字符串操作``numpy.unicode_``。
它们全部基于Python标准库中的字符串方法。
## 字符串操作
方法 | 描述
---|---
[add](https://numpy.org/devdocs/reference/generated/numpy.char.add.html#numpy.char.add)(x1, x2) | 返回两个str或unicode数组的按元素的字符串连接。
[multiply](https://numpy.org/devdocs/reference/generated/numpy.char.multiply.html#numpy.char.multiply)(a, i) | 返回a * i即按元素方式的字符串多重连接。
[mod](https://numpy.org/devdocs/reference/generated/numpy.char.mod.html#numpy.char.mod)(a, values) | 返回ai这是Python 2.6之前的字符串格式迭代针对一对str或unicode的array_likes元素。
[capitalize](https://numpy.org/devdocs/reference/generated/numpy.char.capitalize.html#numpy.char.capitalize)(a) | 返回的拷贝一个只有资本的每个元素的第一个字符。
[center](https://numpy.org/devdocs/reference/generated/numpy.char.center.html#numpy.char.center)(a, width[, fillchar]) | 返回的拷贝一与在长度的字符串居中其元素宽度。
[decode](https://numpy.org/devdocs/reference/generated/numpy.char.decode.html#numpy.char.decode)(a[, encoding, errors]) | 按元素调用str.decode。
[encode](https://numpy.org/devdocs/reference/generated/numpy.char.encode.html#numpy.char.encode)(a[, encoding, errors]) | 逐元素调用str.encode。
[expandtabs](https://numpy.org/devdocs/reference/generated/numpy.char.expandtabs.html#numpy.char.expandtabs)(a[, tabsize]) | 返回每个字符串元素的副本,其中所有制表符都被一个或多个空格替换。
[join](https://numpy.org/devdocs/reference/generated/numpy.char.join.html#numpy.char.join)(sep, seq) | 返回一个字符串该字符串是序列seq中字符串的串联。
[ljust](https://numpy.org/devdocs/reference/generated/numpy.char.ljust.html#numpy.char.ljust)(a, width[, fillchar]) | 返回与元素的数组一个左对齐的长度的字符串宽度。
[lower](https://numpy.org/devdocs/reference/generated/numpy.char.lower.html#numpy.char.lower)(a) | 返回一个将元素转换为小写的数组。
[lstrip](https://numpy.org/devdocs/reference/generated/numpy.char.lstrip.html#numpy.char.lstrip)(a[, chars]) | 对于每一个元素一个,去除了主角返回副本。
[partition](https://numpy.org/devdocs/reference/generated/numpy.char.partition.html#numpy.char.partition)(a) | 将每个元素划分为大约sep。
[replace](https://numpy.org/devdocs/reference/generated/numpy.char.replace.html#numpy.char.replace)e(a, old, new[, count]) | 对于每一个元素一个,返回字符串的副本串中出现的所有旧的换成新的。
[rjust](https://numpy.org/devdocs/reference/generated/numpy.char.rjust.html#numpy.char.rjust)(a, width[, fillchar]) | 返回与元素的数组一个右对齐的长度的字符串宽度。
[rpartition](https://numpy.org/devdocs/reference/generated/numpy.char.rpartition.html#numpy.char.rpartition)(a, sep) | 在最右边的分隔符周围分割(分割)每个元素。
[rsplit](https://numpy.org/devdocs/reference/generated/numpy.char.rsplit.html#numpy.char.rsplit)(a[, sep, maxsplit]) | 在每个元件一个,返回的词的列表字符串中,使用月作为分隔符串。
[rstrip](https://numpy.org/devdocs/reference/generated/numpy.char.rstrip.html#numpy.char.rstrip)(a[, chars]) | 在每个元件一个,返回与除去尾部字符的副本。
[split](https://numpy.org/devdocs/reference/generated/numpy.char.split.html#numpy.char.split)(a[, sep, maxsplit]) | 在每个元件一个,返回的词的列表字符串中,使用月作为分隔符串。
[splitlines](https://numpy.org/devdocs/reference/generated/numpy.char.splitlines.html#numpy.char.splitlines)(a[, keepends]) | 在每个元件一个,返回行的列表中的元素,在断裂线边界。
[strip](https://numpy.org/devdocs/reference/generated/numpy.char.strip.html#numpy.char.strip)(a[, chars]) | 在每个元件一个,其中移除了前缘和后字符返回副本。
[swapcase](https://numpy.org/devdocs/reference/generated/numpy.char.swapcase.html#numpy.char.swapcase)(a) | 按元素返回字符串的副本,该字符串的大写字符转换为小写,反之亦然。
[title](https://numpy.org/devdocs/reference/generated/numpy.char.title.html#numpy.char.title)(a) | 返回字符串或unicode的逐元素标题区分大小写的版本。
[translate](https://numpy.org/devdocs/reference/generated/numpy.char.translate.html#numpy.char.translate)(a, table[, deletechars]) | 对于每一个元素一个返回其中可选的参数中出现的所有字符的字符串拷贝deletechars被删除而剩余的字符已经通过给定的转换表映射。
[upper](https://numpy.org/devdocs/reference/generated/numpy.char.upper.html#numpy.char.upper)(a) | 返回一个数组,其中元素转换为大写。
[zfill](https://numpy.org/devdocs/reference/generated/numpy.char.zfill.html#numpy.char.zfill)(a, width) | 返回用零填充的数字字符串
## 比较
与标准numpy比较运算符不同*char* 模块中的运算符在执行比较之前会删除结尾的空白字符。
方法 | 描述
---|---
[equal](https://numpy.org/devdocs/reference/generated/numpy.char.equal.html#numpy.char.equal)(x1, x2) | 按元素返回x1 == x2
[not_equal](https://numpy.org/devdocs/reference/generated/numpy.char.not_equal.html#numpy.char.not_equal)(x1, x2) | 按元素返回x1= x2
[greater_equal](https://numpy.org/devdocs/reference/generated/numpy.char.greater_equal.html#numpy.char.greater_equal)(x1, x2) | 按元素返回x1> = x2
[less_equal](https://numpy.org/devdocs/reference/generated/numpy.char.less_equal.html#numpy.char.less_equal)(x1, x2) | 按元素返回x1 <= x2
[greater](https://numpy.org/devdocs/reference/generated/numpy.char.greater.html#numpy.char.greater)(x1, x2) | 按元素返回x1> x2
[less](https://numpy.org/devdocs/reference/generated/numpy.char.less.html#numpy.char.less)(x1, x2) | 按元素返回x1 < x2
[compare_chararrays](https://numpy.org/devdocs/reference/generated/numpy.char.compare_chararrays.html#numpy.char.compare_chararrays)(a, b, cmp_op, rstrip) | 使用cmp_op指定的比较运算符对两个字符串数组执行逐元素比较。
## 字符串信息
方法 | 描述
---|---
[count](https://numpy.org/devdocs/reference/generated/numpy.char.count.html#numpy.char.count)(a, sub[, start, end]) | 返回一个数组该数组的子字符串sub的不重叠出现次数在[ startend ] 范围内。
[endswith](https://numpy.org/devdocs/reference/generated/numpy.char.endswith.html#numpy.char.endswith)(a, suffix[, start, end]) | 返回一个布尔值阵列,其是真正的,其中在字符串元素一个结尾的后缀,否则假。
[find](https://numpy.org/devdocs/reference/generated/numpy.char.find.html#numpy.char.find)(a, sub[, start, end]) | 对于每个元素返回找到子字符串sub的字符串中的最低索引。
[index](https://numpy.org/devdocs/reference/generated/numpy.char.index.html#numpy.char.index)(a, sub[, start, end]) | 与相似find但是在未找到子字符串时引发ValueError。
[isalpha](https://numpy.org/devdocs/reference/generated/numpy.char.isalpha.html#numpy.char.isalpha)(a) | 如果字符串中的所有字符都是字母并且至少包含一个字符则对每个元素返回true否则返回false。
[isalnum](https://numpy.org/devdocs/reference/generated/numpy.char.isalnum.html#numpy.char.isalnum)(a) | 如果字符串中的所有字符都是字母数字并且至少包含一个字符则对每个元素返回true否则返回false。
[isdecimal](https://numpy.org/devdocs/reference/generated/numpy.char.isdecimal.html#numpy.char.isdecimal)(a) | 对于每个元素如果元素中只有十进制字符则返回True。
[isdigit](https://numpy.org/devdocs/reference/generated/numpy.char.isdigit.html#numpy.char.isdigit)(a) | 如果字符串中的所有字符都是数字并且至少有一个字符则对每个元素返回true否则返回false。
[islower](https://numpy.org/devdocs/reference/generated/numpy.char.islower.html#numpy.char.islower)(a) | 如果字符串中所有大小写的字符均为小写且至少有一个大小写的字符则对每个元素返回true否则返回false。
[isnumeric](https://numpy.org/devdocs/reference/generated/numpy.char.isnumeric.html#numpy.char.isnumeric)(a) | 对于每个元素如果元素中仅包含数字字符则返回True。
[isspace](https://numpy.org/devdocs/reference/generated/numpy.char.isspace.html#numpy.char.isspace)(a) | 如果字符串中只有空格字符且至少有一个字符则对每个元素返回true否则返回false。
[istitle](https://numpy.org/devdocs/reference/generated/numpy.char.istitle.html#numpy.char.istitle)(a) | 如果该元素是一个带标题的字符串并且至少包含一个字符则为每个元素返回true否则返回false。
[isupper](https://numpy.org/devdocs/reference/generated/numpy.char.isupper.html#numpy.char.isupper)(a) | 如果字符串中所有大小写的字符均为大写且至少有一个字符则为每个元素返回true否则返回false。
[rfind](https://numpy.org/devdocs/reference/generated/numpy.char.rfind.html#numpy.char.rfind)(a, sub[, start, end]) | 在每个元件一个,在字符串中返回指数最高,其中子子被发现,使得子包含[内开始,结束。
[rindex](https://numpy.org/devdocs/reference/generated/numpy.char.rindex.html#numpy.char.rindex)(a, sub[, start, end]) | 与相似rfind但是在未找到子字符串sub时引发ValueError。
[startswith](https://numpy.org/devdocs/reference/generated/numpy.char.startswith.html#numpy.char.startswith)(一个,前缀[,开始,结束] | 返回一个布尔数组是真正的地方在字符串元素一个开头前缀,否则假。
[str_len](https://numpy.org/devdocs/reference/generated/numpy.char.str_len.html#numpy.char.str_len)(a) | 按元素返回lena
## 便利构造函数
方法 | 描述
---|---
[array](https://numpy.org/devdocs/reference/generated/numpy.char.array.html#numpy.char.array)(obj[, itemsize, copy, unicode, order]) | 创建一个 [chararray](https://numpy.org/devdocs/reference/generated/numpy.char.chararray.html#numpy.char.chararray)。
[asarray](https://numpy.org/devdocs/reference/generated/numpy.char.asarray.html#numpy.char.asarray)(obj[, itemsize, unicode, order]) | 将输入转换为 [chararray](https://numpy.org/devdocs/reference/generated/numpy.char.chararray.html#numpy.char.chararray) ,仅在必要时复制数据。
[chararray](https://numpy.org/devdocs/reference/generated/numpy.char.chararray.html#numpy.char.chararray)(shape[, itemsize, unicode, …]) | 提供有关字符串和Unicode值数组的便捷视图。