numpy.unravel_index 说明
来源:互联网 发布:网络机房防雷接地规范 编辑:程序博客网 时间:2024/06/04 01:40
官网的api说明如下:
numpy.unravel_index(indices, dims, order='C')
Converts a flat index or array of flat indices into a tuple of coordinate arrays.
An integer array whose elements are indices into the flattened version of an array of dimensions dims. Before version 1.6.0, this function accepted just one index value.
dims : tuple of ints
The shape of the array to use for unraveling indices.
order : {‘C’, ‘F’}, optional
Determines whether the indices should be viewed as indexing in row-major (C-style) or column-major (Fortran-style) order.
New in version 1.6.0.Returns:unraveled_coords : tuple of ndarray
Each array in the tuple has the same shape as the indices array.
See also
ravel_multi_index
Examples
>>>
>>>np.unravel_index([22,41,37], (7,6))
(array([3, 6, 6]), array([4, 5, 1]))
>>>np.unravel_index([31,41,13], (7,6), order='F')
(array([3, 6, 6]), array([4, 5, 1]))
>>>
>>>np.unravel_index(1621, (6,7,8,9))(3, 1, 4, 1)
例子:
Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element ?
>>>print np.unravel_index(100,(6,7,8))
(1,5,4)
解释:
给定一个矩阵,shape=(6,7,8),即3维的矩阵,求第n个元素的下标是什么?矩阵各维的下标从0开始
如果indices参数是一个标量,那么返回的是一个向量,维数=矩阵的维数,向量的值其实就是在矩阵中对应的下标。如6*7*8*9的矩阵,1621/(7*8*9)=3,(1621-3*7*8*9)/(8*9)=1,(1621-3*7*8*9-1*8*9)/9=4,(1621-3*7*8*9-1*8*9-4*9)=1。所以返回的向量为array(3,1,4,1)
如果indices参数是一个向量的,那么通过该向量中值求出对应的下标。下标的个数就是矩阵的维数,每一维下标组成一个向量,所以返回的向量的个数=矩阵维数。如7*6的矩阵,第22个元素是 3*6+4,所以对应的下标是(3,4),那么返回的值是 array([3]),array([4])
0 0
- numpy.unravel_index 说明
- numpy.unravel_index
- numpy安装说明
- numpy中的sorted方法说明
- Numpy
- numpy
- numpy
- Numpy
- numpy
- numpy
- numpy
- NumPy
- numpy
- numpy
- Numpy
- numpy
- Numpy
- Numpy
- Android Glide 优化用户体验
- struct和typedef struct在C和C++中区别
- java 内存结构
- 欢迎使用CSDN-markdown编辑器
- CodeForces 605 B.Lazy Student(构造)
- numpy.unravel_index 说明
- C#中的readonly跟const用法小结
- UCOS-II时间管理
- mysql 导入txt文件 详解
- 欢迎使用CSDN-markdown编辑器
- CSS3 相对单位rem
- Git7--远程仓库
- PX4代码中的一些简写
- idea eclipse web项目创建