zoukankan      html  css  js  c++  java
  • numpy 笔记

    # url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data'
    # iris = np.genfromtxt(url, delimiter=',', dtype='object')
    1  argsort()【成员函数】 -- 返回排序后的索引
    2  返回数组中最常见值
     vals, counts = np.unique(iris[:, 2], return_counts=True)
     print(vals[np.argmax(counts)])--argmax() 返回最大值的索引
    3 np.where: 返回位置索引【各个维度分开】
       np.argwhere: 返回位置索引【各个维度合并】
       np.argwhere(iris[:, 3].astype(float) > 1.0)[0]  返回第三列第一个大于1.0的位置
    4 返回【10-30】范围数字,小于10变成10, 大于30部分变成30
     np.where(a < 10, 10, np.where(a > 30, 30, a))
     np.clip(a, a_min=10, a_max=30
    5 np.sign()-- >0 return 1,==0 return 0, <0 return -1
    6 np.diff() -- return a[n]-a[n-1]
    7 np.ogrid[:3, 0:4] -- 生成行列向量
    8 np.ravel() -- 将多维向量变成一维

    9  np.unique(x, return_counts, return_index) -- return_index 【返回相同变量第一个元素的索引】

    10 np.repeat()
       np.tile()

    11 arr[::-1]--反转行
         arr[:, ::-1]--反转列
    12 np.mean()--均值
         np.median()--中位数
         np.std()--标准差
    13 np.random.choice(a, sum, p=[0.5, 0.25, 0.25])  在a向量中随机sample sum个值
    14  condition = (iris_2d[:, 2] > 1.5) & (iris_2d[:, 0] < 5.0)
     iris_2d[condition]
     布尔索引--选区第二列大于1.5和第一列小于0.5的行
    15  iris_2d[np.isnan(iris_2d)] = 0 -- 将所有空值置为0
    16  volume = volume[:, np.newaxis]
     # Add the new column
     out = np.hstack([iris_2d, volume])
     --np.newaxis() 扩充一维向量
    17 iris[iris[:, 4] == b'Iris-setosa', [2]]
         选取第四列为'Iris-setosa'的第二列数值

  • 相关阅读:
    SharePoint 2010 获取当前用户的权限
    SharePoint 2010 移除Ribbon菜单中的命令项
    SqlServer2000孤立用户解决方案
    Hello Go!
    XMLHttpRequest对象介绍——1
    Struts 2 简单配置
    asp.net 2.0热贴收藏
    .NET牛人应该知道些什么(转)?
    ASP.net 2.0 中 WebResource.axd 管理资源的一些知识点
    asp.net中的异步页面
  • 原文地址:https://www.cnblogs.com/xidian-mao/p/11273083.html
Copyright © 2011-2022 走看看