import numpy as np
from scipy import signal, stats


def apply_along_axis(func, x, axis):
    return np.apply_along_axis(func, axis, x)


def peak_num(x, axis=-1):
    return apply_along_axis(lambda x: len(signal.find_peaks(x)[0]), x, axis)


def cross_zero_num(x, axis=-1):
    return apply_along_axis(lambda y: len(np.where(np.diff(np.sign(y)))[0]), x, axis)


def abs_max(x, axis=-1):
    return np.max(np.abs(x), axis=axis)


def mean(x, axis=-1):
    return np.mean(x, axis=axis)


def std(x, axis=-1):
    return np.std(x, axis=axis)


def skew(x, axis=-1):
    return stats.skew(x, axis=axis)


def kurtosis(x, axis=-1):
    return stats.kurtosis(x, axis=axis)


def power(x, axis=-1):
    return np.sum(np.square(x), axis=axis)


def diff_mean(x, axis=-1):
    return np.mean(np.diff(x, axis=axis), axis=axis)


def diff_std(x, axis=-1):
    return np.std(np.diff(x, axis=axis), axis=axis)
