⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multiindex.py

📁 finite element library for mathematic majored research
💻 PY
字号:
__author__ = "Anders Logg (logg@simula.no)"__date__ = "2004-11-03 -- 2007-03-08"__copyright__ = "Copyright (C) 2004-2007 Anders Logg"__license__  = "GNU GPL version 3 or any later version"# Modified by Garth N. Wells 2006# Modified by Marie E. Rognes (meg@math.uio.no) 2007# Python modulesimport numpy# FFC common modulesfrom ffc.common.utils import *def build_indices(dims):    "Create a list of all index combinations"    if not dims: return [[]]    ranges = listcopy(dims)    return reduce(outer_join, ranges, [[]])def outer_join(a, b):    """Let a be a list of lists and b a list. We append each element    of b to each list in a and return the resulting list of lists."""    outer = []     for i in range(len(a)):        for j in range(len(b)):            outer += [a[i] + [b[j]]]    return outerclass MultiIndex:    """A MultiIndex represents a list of indices and holds the    following data:        rank    - rank of multiindex        dims    - a list of dimensions        indices - list of all possible multiindex values"""    def __init__(self, dims):        "Create multi index from given list of ranges"        self.rank = len(dims)        self.dims = [len(dim) for dim in dims]        self.indices = build_indices(dims)        return    def __repr__(self):        "Pretty print"        return "rank = %d dims = %s indices = %s" % (self.rank, str(self.dims), str(self.indices))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -