numpy 高阶函数 —— np histogram

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

                       
  • np.diff(a, n=1, axis=-1):n 表示差分的阶数;

    >> x = np.array([1, 2, 4, 7, 0])>> np.diff(x)array([ 123, -7])>> np.diff(x, n=2)array([  1,   1, -10])
         
         
    • 1
    • 2
    • 3
    • 4
    • 5

1. np.histogram

官方文档:numpy.histogram — NumPy v1.12 Manual

  • numpy.histogram(a, bins=10, range=None, normed=False, weights=None, density=None)
    • 返回值,有两个,
      • hist : array
      • bin_edges : array of dtype float,bin edges 的长度要是 hist 的长度加1,bin edges (length(hist)+1),也即 (bin_edges[0], bin_edges[1]) ⇒ hist[0],….,(bin_edges[-2], bin_edges[-1]) ⇒ hist[-1],bin_edges 参数与输入参数的 bins 保持一致;
>>> a = np.arange(5)>>> hist, bin_edges = np.histogram(a, density=True)>>> histarray([ 0.50.0.50.0.0.50.0.50.0.5])>>> hist.sum()2.4999999999999996>>> np.sum(hist*np.diff(bin_edges))1.0                            # hist*np.diff(bin_edges) ⇒ 其实表示一种概率分布;
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/hftytf/article/details/83905143