python-array
2018-07-06 01:19:18来源:博客园 阅读 ()
Creating the array
a = np.array([2,3,4])
b = np.array([(1.5,2,3), (4,5,6)]) 多维
>>> a.shape
(3, 5)
参数在array中的shape命令是返回一个长度为n 的tuple, n 的值和 中括号的层数相同 以 numpy.array([[[1],[2]],[[1], [2]]])为例,调用shape后得到的tuple值为 (2, 2, 1),
第一个 “2”, 去掉最外层括号 [[1],[2]], [[1], [2]] 长度为 2。
第二个 “2”, 第二层括号每个数组的长度, 如[1], [2] 长度为 2。注意,这里面每个维度的数组长度要相同。
第三个 “1”, 第三层括号的数组的长度,如 1 长度为 1。
>>> a.size size命令是在这个array中一共有多少个元素
15
>>> a = np.arange(15).reshape(3, 5) mutable !! the operation change the array’s size.
>>> np.array([1, 2]) + np.array([3, 4])
array([4, 6])
>>> 2 * np.array([1, 2])
array([2, 4])
some operation on array
- len(A) is the size of the first dimension.
- Indexing an n-d array returns an (n ? 1)-darray.
- A.shape is a sequence of the size in each dimension.
* ndarray is a sequence type.
* All values in an array must be of the same type.
* Typically numbers (integers, floating point or complex) or Booleans, but can be any type.
>>> np.zeros(5)
array([ 0., 0., 0., 0., 0.])
>>> np.ones(3) * 5
array([ 5., 5., 5.])
>>> np.linspace(3, -3, 5)
array([3. , 1.5, 0. , -1.5, -3. ])
- an ndarray and a single value: the operation is done between each element of the array and the value; or
- two ndarrays of the same size: the operation is done between pairs of elements in equal positions.
* If L is an array of bool of the same size as A, A[L] returns an array with the elemnts of A where L is True (does not preserve shape).
* If I is an array of integers, A[I] returns an array with the elements of A at indices I (does not preserve shape).
* If A is a 2-darray,
-A[i,j] is element at i, j (like A[i][j]).
- A[i,:] is row i (same as A[i]).
- A[:,j] is column j.
- ":" can be start ":" end.
The tricky question about shape.
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- PackagesNotFoundError: The following packages are not av 2019-07-24
- Windows安装python3.x后,pip list警告!DEPRECATION: The d 2019-04-25
- 小白学习随笔the first week 2019-04-11
- django-rest-framework框架 第四篇 认证Authentication 2019-04-11
- NotImplementedError: Only the following pseudo-classes a 2019-02-17
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash