Python之numpy模块array简短学习
2013-11-14 11:15
141 查看
[b]1、简介[/b]
Python的lists是非常的灵活以及易于使用。但是在处理科学计算相关大数量的时候,有点显得捉襟见肘了。
Numpy提供一个强大的N维数组对象(ndarray),包含一些列同类型的元素,这点和python中lists不同。
Python lists are extremely flexible and really handy, but when dealing with a large
number of elements or to support scientific computing, they show their limits.
One of the fundamental aspects of NumPy is providing a powerful N-dimensional
array object, ndarray, to represent a collection of items (all of the same type).
[b]2、例子[/b]
例子1:创建array数组
例子2:分片
和使用python的list一样
例子3:对整个数组进行操作
对比python list中同样的操作:
例子4:生成器操作
例子5:多个数组之间加法
例子6:多维数组
例子7:arange函数
Python的lists是非常的灵活以及易于使用。但是在处理科学计算相关大数量的时候,有点显得捉襟见肘了。
Numpy提供一个强大的N维数组对象(ndarray),包含一些列同类型的元素,这点和python中lists不同。
Python lists are extremely flexible and really handy, but when dealing with a large
number of elements or to support scientific computing, they show their limits.
One of the fundamental aspects of NumPy is providing a powerful N-dimensional
array object, ndarray, to represent a collection of items (all of the same type).
[b]2、例子[/b]
例子1:创建array数组
In [7]: import numpy as np In [8]: x = np.array([1,2,3]) In [9]: x Out[9]: array([1, 2, 3])
例子2:分片
In [10]: x[1:] Out[10]: array([2, 3])
和使用python的list一样
例子3:对整个数组进行操作
In [11]: x*2 Out[11]: array([2, 4, 6])
对比python list中同样的操作:
In [1]: alist=[1,2,3] In [2]: alist * 2 Out[2]: [1, 2, 3, 1, 2, 3]
例子4:生成器操作
In [12]: l = [1,2,3] In [13]: [2*li for li in l] Out[13]: [2, 4, 6]
例子5:多个数组之间加法
In [14]: a = np.array([1,2,3]) In [15]: b = np.array([3,2,1]) In [16]: a+b Out[16]: array([4, 4, 4])
例子6:多维数组
In [17]: M = np.array([[1,2,3],[4,5,6]]) In [18]: M[1,2] Out[18]: 6
例子7:arange函数
In [19]: range(6) Out[19]: [0, 1, 2, 3, 4, 5] In [20]: np.arange(6) Out[20]: array([0, 1, 2, 3, 4, 5])
相关文章推荐
- python numpy 模块学习
- python 模块学习--Numpy
- python内置array模块,与numpy中的array和list之间的转换
- python中numpy模块的数组(array)和矩阵(matric)比较
- python学习笔记(三)- numpy基础:array及matrix详解
- python--初级学习之numpy模块的安装
- Python数据挖掘学习02--numpy和pandas模块基本使用
- python模块numpy之array()
- Python模块学习 ---- httplib HTTP协议客户端实现
- Python3模块numpy的安装过程
- 我的python学习笔记(3) numpy
- Python基础教程 第10章: 自带电池(模块) 学习笔记
- Python学习笔记:详解random模块和time模块
- 用list去初始化numpy的array数组 numpy的array和python中自带的list之间相互转化
- python学习教程之Numpy和Pandas的使用
- Python中的list与NumPy中array的区别 及相互转换
- Python学习之模块间互相调用方法详解
- Python模块学习 re 正则表达式
- Python 模块学习:os模块
- Python模块学习之HTMLTestRunner生成测试报告