Example #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)
Example #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)
Example #3
0
    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)