这个函数真的不太常见,但是看过例子就知道了,unravel就是拆开,阐明的意思,连起来就是“拆开的索引”。
numpy.unravel_index(indices, shape, order=‘C’)
shape
的数组B拉平后的索引,这个拉平flatten有逐行拉伸开的(对应order=‘C’,默认),也有按列从左到右拉伸开的(对应order=‘F’),*可以看完下面例子再回过来品味*
>>> import numpy as np
>>> xx = np.random.randn(3, 4)
>>>> xx
array([[-1.26992094, 1.53123906, 0.30685343, -1.11830275],
[-0.01614887, -1.65227584, -1.13451848, 1.31552904],
[-0.59878739, 0.00169001, -0.29459984, -0.36798817]])
>>> xx.argmax()
1
# 1就是xx逐行从上到下拉开后最大值的索引(0-based)
>>> np.unravel_index(1, (3,4))
(0, 1)
# 如果在shape为(3,4)的数组按行拉平后,索引为1的元素,正常其位置索引就是(0, 1)
>>> np.unravel_index(1, (3,4),order='F')
(1, 0)
# 如果在shape为(3,4)的数组按列拉平后,索引为1的元素,正常其位置索引就是(1, 0)
numpy.outer(a, b, out=None)
out[i, j] = a[i] * b[j]
>>> im = np.outer(1j*np.linspace(2, -2, 5), np.ones((5,)))
>>> im
array([[0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j],
[0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j],
[0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
[0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j],
[0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j]])
>>> x = np.array(['a', 'b', 'c'], dtype=object)
>>> np.outer(x, [1, 2, 3])
array([['a', 'aa', 'aaa'],
['b', 'bb', 'bbb'],
['c', 'cc', 'ccc']], dtype=object)
numpy.hanning(M)
汉宁窗是通过使用加权余弦形成的锥形
>>> np.hanning(11)
array([0. , 0.0954915, 0.3454915, 0.6545085, 0.9045085, 1. ,
0.9045085, 0.6545085, 0.3454915, 0.0954915, 0. ])
# 以下来自官网例子:
>>> import matplotlib.pyplot as plt
>>> window = np.hanning(51)
>>> plt.plot(window)
[<matplotlib.lines.Line2D object at 0x00000286BF8FC128>]
>>> plt.title("Hann window")
Text(0.5,1,'Hann window')
>>> plt.ylabel("Amplitude")
Text(0,0.5,'Amplitude')
>>> plt.xlabel("Sample")
Text(0.5,0,'Sample')
>>> plt.show()