예제 #1
0
 def _getitemClass(self, index):
     if not isinstance(index, tuple):
         if isinstance(index, list):
             index = tuple(index)
         else:
             index = (index, )
     indexshape = numerix._indexShape(index=index, arrayShape=self.shape)
     if (len(indexshape) > 0 and indexshape[-1] == self.shape[-1]
             and numerix.obj2sctype(index[-1]) != numerix.obj2sctype(bool)):
         return self._OperatorVariableClass()
     else:
         return Variable._OperatorVariableClass(self, baseClass=Variable)
예제 #2
0
 def _getitemClass(self, index):
     if not isinstance(index, tuple):
         if isinstance(index, list):
             index = tuple(index)
         else:
             index = (index,)
     indexshape = numerix._indexShape(index=index, arrayShape=self.shape)
     if (len(indexshape) > 0
         and indexshape[-1] == self.shape[-1]
         and numerix.obj2sctype(index[-1]) != numerix.obj2sctype(bool)):
         return self._OperatorVariableClass()
     else:
         return Variable._OperatorVariableClass(self, baseClass=Variable)
예제 #3
0
파일: variable.py 프로젝트: regmi/fipy
    def __getitem__(self, index):
        """    
        "Evaluate" the `Variable` and return the specified element
      
            >>> a = Variable(value=((3.,4.),(5.,6.)), unit="m") + "4 m"
            >>> print a[1,1]
            10.0 m

        It is an error to slice a `Variable` whose `value` is not sliceable

            >>> Variable(value=3)[2]
            Traceback (most recent call last):
                  ...
            IndexError: 0-d arrays can't be indexed

        """
        return self._UnaryOperatorVariable(lambda a: a[index], 
                                           operatorClass=self._getitemClass(index=index), 
                                           opShape=numerix._indexShape(index=index, arrayShape=self.shape),
                                           unit=self.getUnit(),
                                           canInline=False)