Numpy使用1
来源:互联网 发布:知乎 留学中介 编辑:程序博客网 时间:2024/05/14 15:44
Numpy介绍
NumPy is the fundamental package for scientific computing with Python. It contains among other things:
- a powerful N-dimensional array object
- sophisticated (broadcasting) functions
- tools for integrating C/C++ and Fortran code
- useful linear algebra, Fourier transform, and random number capabilities
Numpy常常用在python科学计算中,最主要的能力就是提供了N-dimensional array(N维数组)的能力,可能有的人说python中不是有list嘛,list就可以当做数组用啊,说的没错,简单的数据的确是可以的,我问几个问题,如果你觉得list之类的都可以搞定,那么咱们就可以宣告numpy的死亡了
- 如何存储RGB图像
- 如何存储结构化的数据
- 如何高效存储和索引多维数组
- 如何高效的进行数据的切片和组装
很明显,这些list都是做不到的,如果你有类似的这类需求的话,那么numpy应该不会让你失望。
官方网址:HERE
Numpy的安装
我的机器是ubuntu14.04(64 位),建议使用pip安装,pip是个python的包管理器,通过它可以很方便的进行安装、卸载、升级
sudo apt-get install python-pip # install pipsudo pip install numpy # install numpy
如果是windows的话,同样可以先安装pip,再使用pip安装numpy,不过过程稍微麻烦点,请大家自行百度
Getting Started
安装好以后,我们来测试下,并写段小代码体验下numpy的强大功能
import numpy as np
如果你import没有出错的化,就表示你已经成功安装好了
下面我们在ipython的交互式环境下写点代码,体验下numpy的功能
(1)创建3*3的全0矩阵
In [1]: import numpy as npIn [2]: all_zero =np.zeros((3,3))In [3]: all_zeroOut[3]: array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]])In [4]:
(2)从python的list种初始化numpy矩阵
In [8]: test_list = [1,3,5,6,7]In [9]: array_numpy = np.arranp.array np.array_equal np.array_repr np.array_strnp.array2string np.array_equiv np.array_split In [9]: array_numpy = np.array(test_list)In [10]: array_numpyOut[10]: array([1, 3, 5, 6, 7])In [11]:
(3)创建多维数组(3*4*4)
In [11]: array_n_dim = np.ones((3,4,4),dtype='int8')In [12]: array_n_dimOut[12]: array([[[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]], dtype=int8)In [13]:
(4)从文本load结构化数据
假设当前目录下有个文本文件numpy_test.txt,内容是
In [14]: test_numpy = np.loadtxt('numpy_test.txt', str, delimiter=':')In [15]: test_numpyOut[15]: array([['1', '2'], ['3', '4'], ['5', '6'], ['7', '7'], ['8', '1']], dtype='|S1')In [16]:
相信到这已经可以说明numpy的强大之处,其实还有很多的优秀特性还没介绍,下个博客继续
0 0
- Numpy使用1
- Numpy 使用教程 1
- 【CS231N】Numpy 使用入门 (1)
- numpy使用
- NumPy使用
- numpy 使用
- numpy使用
- python numpy:1 numpy.array和numpy.matrix常用函数使用
- Numpy(1)
- numpy module 1 -- Numpy tutorial
- python numpy使用
- numpy where 的使用
- python numpy使用
- Numpy Python 使用感想
- python之Numpy使用
- NumPy使用(一)
- NumPy使用(二)
- python numpy使用
- Android资料
- Qt简介
- 服务器查询访问参数
- MySQL 5.7.x 数据库名中文访问出错或表内中文显示?? 解决方法
- ionic 用 cordova插件,ping++方式 实现支付宝,微信支付
- Numpy使用1
- 支付宝即时交易,日期工具类
- 特征处理(Feature Processing)
- JAVA Scanner的用法
- GenerateNewFileThroughDeleteDataByHaijian
- 各种语言的helloworld
- 关于nginx 配置gzip 压缩js问题 请求合并问题
- pm2 的使用
- 安装bower