numpy.linalg.norm , . mag , , , :
0 (.. mag <- mag - np.mean(mag) --> 0).
above . NumPy 1, 0, , "", , . , 0, np.std.
shape undefined, : (). , numpy.mean, mag.shape , NumPy. np.mean NumPy.
:
In [56]: mag = 10
In [57]: type(mag)
Out[57]: int
In [58]: mag -= np.mean(mag)
In [59]: type(mag)
Out[59]: numpy.float64
, indicator , , , .
, , mag ... ... 10 th = 1:
In [60]: mag = 10
In [61]: mag -= np.mean(mag)
In [62]: mag.shape
Out[62]: ()
In [63]: th = 1
In [64]: above = np.where(mag >= th * np.std(mag))
In [65]: indicator = np.zeros(mag.shape)
In [66]: indicator
Out[66]: array(0.0)
In [67]: mag
Out[67]: 0.0
In [68]: indicator[above] = 1
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-67-adf9cff7610a> in <module>()
----> 1 indicator[above] = 1
IndexError: too many indices for array
, - , . MATLAB , data , . , pandas DataFrame, numpy, , MATLAB. , x, y z , numpy, .
def segment_energy(data, th):
mag = np.sqrt(np.sum(data.loc[:, ['x','y','z']]** 2.0, axis=1))
mag = np.array(mag)
mag -= np.mean(mag)
above = np.where(mag >= th * np.std(mag))
indicator = np.zeros(mag.shape)
indicator[above] = 1
plt.plot(mag)
plt.plot(indicator * 1000, 'r')
plt.show()
- MATLAB NumPy. loc, pandas DataFrame , . NumPy, .
numpy.linalg.norm, , . 2D, axis=1, :
mag = np.linalg.norm(data.loc[:, ['x', 'y', 'z']], axis=1)
NumPy .