安装numpy

windows安装pip即可,具体方法参考pip官网 http://pip-cn.readthedocs.io/en/latest/installing.html

安装方法:pip install  numpy-1.14.3-cp27-none-win_amd64.whl

功能介绍:

  • 提供数组的矢量化操作,所谓矢量化就是不用循环就能将运算符应用到数组中的每个元素中。
  • 提供数学函数应用到每个数组中元素
  • 提供线性代数,随机数生成,傅里叶变换等数学模块
  • ndarray:numpy库的心脏,多维数组,具有矢量运算能力,快速、节省空间在array中的数据类型是一致的

ndarray:

  ndarray具有多维性。ndarray的元素可以通过索引的方式进行访问。在Numpy中,ndarray的维度称为axes。axes的大小称为rank。列如ndarray[1,2,1],它的维度为1,rank的值为1,因为只有一维。索引从0开始。

print np.identity(3,int)  #单位矩阵

结果:

[[1 0 0]
[0 1 0]
[0 0 1]]

零矩阵:

print np.zeros((3,4)) #零矩阵
print np.zeros(3) #零矩阵

结果:

[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
[0. 0. 0.]

全一矩阵:

print np.ones((3,3))
print np.ones(4)

结果:

[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
[1. 1. 1. 1.]

矩阵乘法:

a=((1,2,3),(4,5,6),(7,8,9))
a=np.array(a)
print np.dot(2,a)

结果:

[[ 2  4  6]
[ 8 10 12]
[14 16 18]]

矩阵大小:

a=((1,2,3),(4,5,6),(7,8,9))
a=np.array(a)
print a.ndim

结果:

2

行求和,列求和

a=((1,2,3),(4,5,6),(7,8,9))
a=np.array(a)
print np.sum(a,axis=1)
print np.sum(a,axis=0)
#axis=1表示矩阵a的行求和,axis=0表示在列求和

结果:

[ 6 15 24]
[12 15 18]

转置矩阵:

a=((1,2,3),(4,5,6),(7,8,9))
a=np.array(a)
print a.T

结果:

[[1 4 7]
[2 5 8]
[3 6 9]]

其他的一些:

a=((1,2,3),(4,5,6),(7,8,9))
a=np.array(a)
print np.random.random((3,3)) #random模块的random函数,生成随机数
print np.mean(a) #求平均数
print np.max(a) #求最大值
print np.min(a)
print np.std(a) #求标准差
print np.arange(0,20,step=2) #arange可以指定起点,终点,步长进行数组创建
print np.linspace(0, 20, 10) #等同于下面的这个
print np.linspace(start=0, stop=20, num=10)
#直接指定开始,结束然后指定个数进行创建。
print np.random.normal(10,100,size=10) #产生服从高斯分布的随机数,三个参数分别是平均值,方差,个数

结果:

[[0.18149469 0.82166642 0.89837593]
[0.07947753 0.65715104 0.23933089]
[0.34254456 0.19185617 0.17856812]]
5.0
9
1
2.581988897471611
[ 0 2 4 6 8 10 12 14 16 18]
[ 0. 2.22222222 4.44444444 6.66666667 8.88888889 11.11111111
13.33333333 15.55555556 17.77777778 20. ]
[ 0. 2.22222222 4.44444444 6.66666667 8.88888889 11.11111111
13.33333333 15.55555556 17.77777778 20. ]
[ 36.25896713 75.73646837 -90.97435221 -87.55378736 192.75253223
-59.32404814 256.30659631 -161.95343956 5.39389542 -62.17649294]

numpy的一些用法的更多相关文章

  1. Python Numpy shape 基础用法(转自他人的博客,如涉及到侵权,请联系我)

    Python Numpy shape 基础用法 shape函数是numpy.core.fromnumeric中的函数,它的功能是读取矩阵的长度,比如shape[0]就是读取矩阵第一维度的长度.它的输入 ...

  2. Numpy的简单用法

    Numpy的简单用法 import numpy as np 一.创建ndarray对象 列表转换成ndarray: >>> a = [1,2,3,4,5] >>> ...

  3. numpy中线性代数用法

    numpy中线性代数用法 矩阵乘法 >>> import numpy as np >>> x=np.array([[1,2,3],[4,5,6]]) >> ...

  4. numpy.asmatrix的用法

    学习的过程中,遇到了asmatrix的用法,看了一下官方文档,明白了. numpy.asmatrix numpy.asmatrix(data, dtype=None)[source] Interpre ...

  5. 数据科学:numpy.where() 的用法

    原文出处:numpy.where() 用法讲解 原创作者:massquantity numpy.where() 有两种用法: 1. np.where(condition, x, y) 满足条件(con ...

  6. Py修行路 NumPy模块基本用法

    NumPy系统是Python的一种开源的数值计算扩展,一个用python实现的科学计算包.这种工具可用来存储和处理大型矩阵,比Python自身的嵌套列表(nested list structure)结 ...

  7. Numpy的基础用法

    1.用Numpy创建数组 numpy.array(object):创建数组,与array.array(typecode[, initializer])不同,array.array()只能创建一维数组 ...

  8. numpy.random模块用法总结

    from numpy import random numpy.random.uniform(low=0.0, high=1.0, size=None) 生出size个符合均分布的浮点数,取值范围为[l ...

  9. anaconda及jupyter notebook的使用之numpy模块的用法(2)

    今日内容概要 numpy模块结束 ndarray创建 numpy内置方法 索引与切片(花式索引.布尔索引) 常用函数 统计方法 随机数 numpy的内置方法 import numpy as np 1. ...

  10. numpy.random模块用法小结

    原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/9751471.html 1.np.random.random()函数参数 np.random.r ...

随机推荐

  1. django model_fields_validators 前端页面编辑自定义验证

    # model_field_validators.py import re from django.core.exceptions import ValidationError from django ...

  2. UI-UIButton、UILable、UITextField总结

    UIButton按钮====================================================== 第一.UIButton的定义 UIButton *button=[[U ...

  3. brew: Nginx https config

    下载安装Brew: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/mas ...

  4. windows7自动登录后锁定 & 其他VBS

    首先设置自动登录(原已设置登录密码),在开始菜单搜索框输 入 “netplwiz” 按 回车,打开高级用户控制面板,然后取消对“要使用本机,用户需输入用户名和密码(E)”项的勾选,系统弹出窗口要求输入 ...

  5. Flask 的整体流程

    Flask 的整体流程 封装 requestContext 对象, full_dispatch_request(视图函数 执行), response返回 从app.run() 开始 -->> ...

  6. 在 Ubuntu 上搭建 Hadoop 分布式集群 Eclipse 开发环境

    一直在忙Android FrameWork,终于闲了一点,利用空余时间研究了一下Hadoop,并且在自己和同事的电脑上搭建了分布式集群,现在更新一下blog,分享自己的成果. 一 .环境 1.操作系统 ...

  7. javascript 的智能提示intellisence用法

    转载自:http://blog.csdn.net/applewangpai/article/details/23517087   引用指令reference Visual Studio 2012支持的 ...

  8. aac adts & LATM封装码流分析

    本文继续上一篇文章的内容,介绍一个音频码流处理程序.音频码流在视频播放器中的位置如下所示. 本文中的程序是一个AAC码流解析程序.该程序可以从AAC码流中分析得到它的基本单元ADTS frame,并且 ...

  9. Thrift之java实例

    一.java实例 1.下载与安装thrift工具 http://thrift.apache.org/download/ .服务器代码 服务Test实现类 package com.zychen.thri ...

  10. 时间由yyyy-MM-dd HH:mm:ss专为yyyy-MM-dd

    (1)类用date 注意:如果用string会报错  页面无法使用string(...): (2)数据库表 (3)页面