1、简介

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).

2、例子

例子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])

最新文章

  1. IOS 开发小技巧总结
  2. 遇到的Exception/error及解决办法记录汇总
  3. for 循环中 continue
  4. TJI读书笔记15-持有对象
  5. Windows下解压版mysql的安装方法
  6. BOOL in Object-C
  7. Xcode的command+shift+o是一个不错的工具
  8. java分页
  9. getchar() 和 scanf("%c")的区别
  10. CUBRID学习笔记 46 PREPARED set Do
  11. 读《java核心技术卷一》有感
  12. wp8.1 全球化解决办法
  13. c#winform使用WebBrowser 大全[超长文转载]
  14. xml和html之间相互转换
  15. Q - 密码(第二季水)
  16. Hibernate的介绍
  17. 浅谈Linux ftp服务器相关配置
  18. B树,B+树,B*树
  19. [Shapefile C Library]读写shp图形(C++&.net Wapper)
  20. React/anu实现Touchable

热门文章

  1. HDU2874 LCA Tarjan
  2. IOS系统配置FFMEPG
  3. IIS ApplicationPoolIdentity(配置IIS讀寫網站文件)
  4. java zip解压
  5. ARM总线方面知识
  6. javascript 之基本包装类型--04
  7. LINUX 笔记-命令执行顺序 && ,||
  8. PhiloGL学习(1)——场景创建及方块欲露还羞出水面
  9. JavaScript OOP 之 this指向
  10. swift 之设计模式 适配器