当前位置: 首页>>代码示例>>Python>>正文


Python ArrayMath.section方法代码示例

本文整理汇总了Python中org.meteoinfo.data.ArrayMath.section方法的典型用法代码示例。如果您正苦于以下问题:Python ArrayMath.section方法的具体用法?Python ArrayMath.section怎么用?Python ArrayMath.section使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.meteoinfo.data.ArrayMath的用法示例。


在下文中一共展示了ArrayMath.section方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __getitem__

# 需要导入模块: from org.meteoinfo.data import ArrayMath [as 别名]
# 或者: from org.meteoinfo.data.ArrayMath import section [as 别名]
    def __getitem__(self, indices):
        #print type(indices)            
        if not isinstance(indices, tuple):
            inds = []
            inds.append(indices)
            indices = inds
            
        if self.rank == 0:
            return self
        
        if len(indices) != self.rank:
            print 'indices must be ' + str(self.rank) + ' dimensions!'
            return None

        ranges = []
        flips = []
        iszerodim = True
        for i in range(0, self.rank):   
            if isinstance(indices[i], int):
                sidx = indices[i]
                eidx = indices[i]
                step = 1
            else:
                sidx = 0 if indices[i].start is None else indices[i].start
                eidx = self.getshape()[i]-1 if indices[i].stop is None else indices[i].stop-1
                step = 1 if indices[i].step is None else indices[i].step
            if sidx != eidx:
                iszerodim = False
            if step < 0:
                step = abs(step)
                flips.append(i)
            if sidx >= self.shape[i]:
                raise IndexError()
            rr = Range(sidx, eidx, step)
            ranges.append(rr)
        r = ArrayMath.section(self.array, ranges)
        if iszerodim:
            return r.getObject(0)
        else:
            for i in flips:
                r = r.flip(i)
            rr = Array.factory(r.getDataType(), r.getShape());
            MAMath.copy(rr, r);
            return MIArray(rr)
开发者ID:ccnasyq,项目名称:MeteoInfoLab,代码行数:46,代码来源:miarray.py

示例2: __getitem__

# 需要导入模块: from org.meteoinfo.data import ArrayMath [as 别名]
# 或者: from org.meteoinfo.data.ArrayMath import section [as 别名]
    def __getitem__(self, indices):
        #print type(indices)
        if not isinstance(indices, tuple):
            inds = []
            inds.append(indices)
            indices = inds
        
        if len(indices) != self.ndim:
            print 'indices must be ' + str(self.ndim) + ' dimensions!'
            return None
            
        #origin = []
        #size = []
        #stride = []
        dims = []
        ranges = []
        flips = []
        iszerodim = True
        for i in range(0, self.ndim):  
            k = indices[i]
            if isinstance(indices[i], int):
                sidx = k
                eidx = k
                step = 1                
            elif isinstance(k, slice):
                sidx = 0 if k.start is None else k.start
                eidx = self.dims[i].getLength()-1 if k.stop is None else k.stop-1
                step = 1 if k.step is None else k.step
            elif isinstance(k, tuple) or isinstance(k, list):
                dim = self.dims[i]
                sidx = dim.getValueIndex(k[0])
                if len(k) == 1:
                    eidx = sidx
                    step = 1
                else:                    
                    eidx = dim.getValueIndex(k[1])
                    if len(k) == 2:
                        step = 1
                    else:
                        step = int(k[2] / dim.getDeltaValue)
            else:
                print k
                return None

            if sidx >= self.shape[i]:
                raise IndexError()
                
            if sidx != eidx:
                iszerodim = False
            if step < 0:
                step = abs(step)
                flips.append(i)
            rr = Range(sidx, eidx, step)
            ranges.append(rr)
            #origin.append(sidx)
            n = eidx - sidx + 1
            #size.append(n)
            #stride.append(step)
            if n > 1:
                dim = self.dims[i]
                dims.append(dim.extract(sidx, eidx, step))
                    
        #r = ArrayMath.section(self.array.array, origin, size, stride)
        r = ArrayMath.section(self.array.array, ranges)
        if iszerodim:
            return r.getObject(0)
        else:
            for i in flips:
                r = r.flip(i)
            rr = Array.factory(r.getDataType(), r.getShape());
            MAMath.copy(rr, r);
            array = MIArray(rr)
            data = DimArray(array, dims, self.fill_value, self.proj)
            return data
开发者ID:honley,项目名称:MeteoInfoLab,代码行数:76,代码来源:dimarray.py

示例3: __getitem__

# 需要导入模块: from org.meteoinfo.data import ArrayMath [as 别名]
# 或者: from org.meteoinfo.data.ArrayMath import section [as 别名]
    def __getitem__(self, indices):
        #print type(indices)            
        if not isinstance(indices, tuple):
            inds = []
            inds.append(indices)
            indices = inds
            
        allint = True
        aindex = self.array.getIndex()
        i = 0
        for ii in indices:
            if isinstance(ii, int):
                if ii < 0:
                    ii = self.shape[i] + ii
                aindex.setDim(i, ii)
            else:
                allint = False
                break;
            i += 1
        if allint:
            return self.array.getObject(aindex)
            
        if self.ndim == 0:
            return self
        
        if len(indices) != self.ndim:
            print 'indices must be ' + str(self.ndim) + ' dimensions!'
            raise IndexError()

        ranges = []
        flips = []
        onlyrange = True
        alllist = True
        isempty = False
        nshape = []
        for i in range(0, self.ndim):  
            k = indices[i]
            if isinstance(k, int):
                if k < 0:
                    k = self._shape[i] + k
                sidx = k
                eidx = k
                step = 1
                alllist = False
            elif isinstance(k, slice):
                sidx = 0 if k.start is None else k.start
                if sidx < 0:
                    sidx = self._shape[i] + sidx
                eidx = self._shape[i] if k.stop is None else k.stop
                if eidx < 0:
                    eidx = self._shape[i] + eidx
                eidx -= 1                    
                step = 1 if k.step is None else k.step
                alllist = False
            elif isinstance(k, (list, tuple, MIArray)):
                if isinstance(k, MIArray):
                    k = k.aslist()
                if isinstance(k[0], bool):
                    kk = []
                    for i in range(len(k)):
                        if k[i]:
                            kk.append(i)
                    k = kk                        
                onlyrange = False
                ranges.append(k)
                continue
            else:
                print k
                return None
            if step < 0:
                step = abs(step)
                flips.append(i)
                if eidx < sidx:
                    tempidx = sidx
                    sidx = eidx + 2
                    eidx = tempidx
            if sidx >= self.shape[i]:
                raise IndexError()
            if eidx < sidx:
                isempty = True
            else:
                rr = Range(sidx, eidx, step)
                ranges.append(rr)
            nshape.append(eidx - sidx + 1 if eidx - sidx >= 0 else 0)

        if isempty:
            r = ArrayUtil.zeros(nshape, 'int')
            return MIArray(r)
            
        if onlyrange:
            r = ArrayMath.section(self.array, ranges)
        else:
            if alllist:
                r = ArrayMath.takeValues(self.array, ranges)
            else:
                r = ArrayMath.take(self.array, ranges)
        if r.getSize() == 1:
            r = r.getObject(0)
            if isinstance(r, Complex):
                return complex(r.getReal(), r.getImaginary())
#.........这里部分代码省略.........
开发者ID:meteoinfo,项目名称:MeteoInfoLab,代码行数:103,代码来源:miarray.py


注:本文中的org.meteoinfo.data.ArrayMath.section方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。