一个很棒的矩阵索引工具。提出了一个新的概念“单索引”(如在Matlab中)来索引矩阵中的元素。用Matlab样式索引(从1开始)交换Python样式索引(从0开始)
pindex的Python项目详细描述
简介
摘要
一个用于索引矩阵的很棒的工具。提出了一个新的概念“单索引”(如在Matlab中)来索引矩阵中的元素。用Matlab样式索引(从1开始)交换Python样式索引(从0开始)
关键词
索引,矩阵,单索引,索引样式
新功能:
- fix some bugs
功能:
- propose single index
- change to (back from) matlab-style index
- arithmetic of the index
内容
课程:
SingleIndex: wrapper of int, list, slice Index: array of SingleIndex
接口:
Arith: arithmetic of index
功能:
irange: interval-like index
语法
基本语法
导入:
import pindex # python for index
示例:
ind = SingleIndex([1,2,3]) # construct a single index s = ind('helloworld') # index(array) == array[index] print(s) A = np.array([[1,2,6],[3,4,5]]) B = ind(A) print(B) # index matrix with single index as in matlab ind.py2matlab() # change to matlab style s = ind('helloworld') print(s) # output: hel ind = Index([1,2,3]) # for 1dim array, Index == SingleIndex ss = ind('helloworld') print(ss) ind = Index(([1,2],[3,4])) # construct multi-index try: ss = ind(['hello', 'world']) print(ss) except: ind.py2matlab() ss = ind(['hello', 'world']) print(ss)
注意:
ind = SingleIndex([1,2,3]) A = [[1,2,6],[3,4,5]] B = ind(A) # pindex.py thinks A is a list (of lists, with length 2) instead of matrix ind = Index(([0,1],[0,1])) # this is ok, since you use multi-index