>>> import numpy as np
>>> L = np.random.random(100)
>>> L
array([0.82846513, 0.19136857, 0.27040895, 0.56103442, 0.90238039,
0.85178834, 0.41808196, 0.39347627, 0.01622051, 0.29921337,
0.35377822, 0.89350267, 0.78613657, 0.77138693, 0.42005486,
0.77602514, 0.46430814, 0.18177017, 0.8840256 , 0.71879227,
0.6718813 , 0.25656363, 0.43080182, 0.01645358, 0.23499383,
0.51117131, 0.29200924, 0.50189351, 0.49827313, 0.10377152,
0.44644312, 0.96918917, 0.73847112, 0.71955061, 0.89304339,
0.96267468, 0.19705023, 0.71458996, 0.16192394, 0.86625477,
0.62382025, 0.95945512, 0.52414204, 0.03643288, 0.72687158,
0.00390984, 0.050294 , 0.99199232, 0.2122575 , 0.94737066,
0.45154055, 0.99879467, 0.64750149, 0.70224071, 0.42958177,
>>> sum(L)
52.03087325680787
>>> np.sum(L)
52.030873256807865
big_array = np.random.rand(1000000)

>>> np.min(big_array)
4.459899819675428e-06 >>> big_array.max()
0.9999999038835905 >>> X = np.arange(16).reshape(4,4)
>>> X
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]]) >>> np.sum(X)
120 >>> np.sum(X,axis=0)
array([24, 28, 32, 36]) >>> np.sum(X,axis=1)
array([ 6, 22, 38, 54]) >>> np.prod(X)
0 >>> np.prod(X + 1)
2004189184 >>> np.mean(X)
7.5 >>> np.median(X)
7.5 >>> V = np.array([1,1,2,2,10])
>>> np.mean(V)
3.2 >>> np.median(V)
2.0 >>> np.percentile(big_array,q=50)
0.499739362948878
>>> for percent in [0,25,50,75,100]:
... print(np.percentile(big_array,q=percent))
...
4.459899819675428e-06
0.24975691457362903
0.499739362948878
0.7498092671305248
0.9999999038835905 >>> X = np.random.normal(0,1,size=1000000)
>>> np.mean(X)
0.00026937497963613595 >>> np.std(X)
0.9996291605602685 >>> np.min(X)
-5.333919783687649 >>> np.argmin(X)
661675 >>> np.argmax(X)
774515 >>> X[91952]
-0.5633231945005146 >>> np.max(X)
4.53612178954408 >>> x = np.arange(16)
>>> x
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) >>> np.random.shuffle(x)
>>> x
array([ 2, 7, 8, 4, 14, 15, 6, 11, 13, 1, 12, 0, 9, 10, 3, 5]) >>> np.sort(x)
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) >>> x.sort()
>>> x
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) >>> x = np.random.randint(10, size=(4,4))
>>> x
array([[7, 0, 0, 7],
[0, 3, 5, 7],
[9, 7, 3, 9],
[4, 0, 9, 2]]) >>> np.sort(x)
array([[0, 0, 7, 7],
[0, 3, 5, 7],
[3, 7, 9, 9],
[0, 2, 4, 9]]) >>> np.sort(x,axis=0)
array([[0, 0, 0, 2],
[4, 0, 3, 7],
[7, 3, 5, 7],
[9, 7, 9, 9]]) >>> np.partition(X,3)
array([-5.33391978, -5.13221775, -4.86828137, ..., 0.16378629,
1.09224809, 1.00502282])

06.numpy聚合运算的更多相关文章

  1. Numpy入门 - 数组聚合运算

    本节主要讲解numpy的几个常用的聚合运算,包括求和sum.求平均mean和求方差var. 一.求和sum import numpy as np arr = np.array([[1, 2, 3], ...

  2. pandas之聚合运算

    通过聚合运算可以得到我们比较感兴趣的数据以方便处理 import pandas as pd import numpy as np # 先创建一组数据表DataFrame df = pd.DataFra ...

  3. MongoDB聚合运算之group和aggregate聚集框架简单聚合(10)

    聚合运算之group 语法: db.collection.group( { key:{key1:1,key2:1}, cond:{}, reduce: function(curr,result) { ...

  4. Swift - 11 - nil聚合运算

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  5. Dynamics 365 CE中使用FetchXML进行聚合运算

    微软动态CRM专家罗勇 ,回复328或者20190429可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me! Dynamics 365 Customer Engagement ...

  6. NumPy 位运算

    NumPy 位运算 NumPy "bitwise_" 开头的函数是位运算函数. NumPy 位运算包括以下几个函数: 函数 描述 bitwise_and 对数组元素执行位与操作 b ...

  7. 3:django models Making queries 高级进阶--聚合运算

    在前一遍文章django models Making queries里面我们提到了django常用的一些检索数据库的内容, 下面我们来看一下更为高级的检索聚合运算 这是我们要用到的模型 class A ...

  8. NumPy算数运算

    NumPy - 算数运算 用于执行算术运算(如add(),subtract(),multiply()和divide())的输入数组必须具有相同的形状或符合数组广播规则. 示例 import numpy ...

  9. C#聚合运算方法

    Aggregate 对集合值执行自定义聚合运算 Average 计算集合平均值 Count 对集合的元素惊醒计数,还可以仅对满足某一谓词函数的元素进行计数 LongCount 对大型集合中的元素进行计 ...

随机推荐

  1. Oracle数据库之——分组查询,子查询及添加,更新,删除

    分组查询 写的顺序: select...from...where... group by...having...order by... 执行顺序: from...where...group by... ...

  2. Microsoft Exchange远程代码执行漏洞(CVE-2020-16875)

    Microsoft Exchange远程代码执行漏洞(CVE-2020-16875) 漏洞信息: 由于对cmdlet参数的验证不正确,Microsoft Exchange服务器中存在一个远程执行代码漏 ...

  3. WAMP3.1.3自定义根目录

    1.首先找到httpd.conf 文件,搜索documentroot 修改前:DocumentRoot "${INSTALL_DIR}/www" <Directory &qu ...

  4. java 读取text内容

    public static String readToString(String fileName) { String encoding = "UTF-8"; File file ...

  5. io流读写操作

    /** * * DOC 将F盘下的test.jpg文件,读取后,再存到E盘下面. * * @param args * @throws Exception */ public static void m ...

  6. Flink-v1.12官方网站翻译-P014-Flink Architecture

    Flink架构 Flink是一个分布式系统,为了执行流式应用,需要对计算资源进行有效的分配和管理.它集成了所有常见的集群资源管理器,如Hadoop YARN.Apache Mesos和Kubernet ...

  7. canal-adapter1.1.14最新版本安装的过程中出现的NullPointerException异常

    记录一下我在安装 canal-adapter1.1.14最新版本安装的过程中出现的NullPointerException异常 以下是我的canal-adapter/logs文件夹内adapter.l ...

  8. Codeforces Round #697 (Div. 3) G. Strange Beauty (DP,数学)

    题意:给你一组数,问你最少删去多少数,使得剩下的数,每个数都能整除数组中其它某个数或被数组中其它某个数整除. 题解:我们直接枚举所有因子,\(dp[i]\)表示\(i\)在数组中所含的最大因子数(当我 ...

  9. hdu3461 Code Lock

    Problem Description A lock you use has a code system to be opened instead of a key. The lock contain ...

  10. Codeforces ECR86 C. Yet Another Counting Problem(规律,区间)

    题意:给你两个正整数a和b,询问q次,每次给你一个区间[l,r],问[l,r]中有多少数字满足:x%a%b!=a%b%a. 题解:看公式无从下手的题,一般都是要找规律的.首先,我们知道,假如x%a%b ...