numpy随记

  1. meshgrid函数,用两个坐标轴上的点在平面上画格
    用法:
    [X, Y] = meshgrid(x, y)
    [X,Y]=meshgrid(x)与[X,Y]=meshgrid(x,x)是等同的
    [X,Y,Z]=meshgrid(x,y,z)生成三维数组,可用来计算三变量的函数和绘制三维立体图。
  2. np.r_是按列连接两个矩阵,就是把两矩阵上下相加,要求列数相等,类似于pandas中的concat()。
    np.c_是按行连接两个矩阵,就是把两矩阵左右相加,要求行数相等,类似于pandas中的merge()。
    例:
    import numpy as np
    a = np.array([1, 2, 3])
    b = np.array([4, 5, 6])
    c = np.c_[a,b]
    print(np.r_[a,b])
    print(c)
    print(np.c_[c,a])


    image.png
  3. np.sum用法
    axis=0,即行压缩,axis=1,即列压缩
    keepdims : bool, optional(保持缩小轴原尺寸)
    If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
    If the default value is passed, then keepdims will not be passed through to the sum method of sub-classes of ndarray, however any non-default value will be. If the sub-classes sum method does not implement keepdims any exceptions will be raised.


    image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 永远不要放弃选择的权利。 一般人遇到事情,是别人刺激自己,然后做出反应。别人的行为刺激引导决定了我们的反应。比如说...
    Sonny越阅读 6,964评论 5 13
  • 为什么人总会记得某些日子,正所谓的纪念日!
    Suansuan阅读 389评论 0 0
  • 因为前些天想贷款买房子,开盘前,交了意向金。结果开盘那天房价高的超了预算,所以房子就没买,所以今天上午去问意向金的...
    雨忆半阳阅读 467评论 0 0