(self, i, value)
Sets a single item, a row or a column of the matrix

        @param i: if a single integer, sets the M{i}th row as a list. If a
          slice, sets the corresponding rows from another L{Matrix} object.
          If a 2-tuple, the first element of the tuple is used to select a row
          and the second is used to select a column.
        @param value: the new value
Sets a single item, a row or a column of the matrix
Sets a single item a row or a column of the matrix
def __setitem__(self, i, value):
        """Sets a single item, a row or a column of the matrix

        @param i: if a single integer, sets the M{i}th row as a list. If a
          slice, sets the corresponding rows from another L{Matrix} object.
          If a 2-tuple, the first element of the tuple is used to select a row
          and the second is used to select a column.
        @param value: the new value
        """
        if isinstance(i, int):
            # Setting a row
            if len(value) != len(self._data[i]):
                raise ValueError("new value must have %d items" % self._ncol)
            self._data[i] = list(value)
        elif isinstance(i, slice):
            # Setting multiple rows
            if len(value) != len(self._data[i]):
                raise ValueError("new value must have %d items" % self._ncol)
            if any(len(row) != self._ncol for row in value):
                raise ValueError("rows of new value must have %d items" % self._ncol)
            self._data[i] = [list(row) for row in value]
        elif isinstance(i, tuple):
            try:
                first = i[0]
            except IndexError:
                first = slice(None)
            try:
                second = i[1]
            except IndexError:
                second = slice(None)
            if type(first) == slice and type(second) == slice:
                # Setting a submatrix
                # TODO
                raise NotImplementedError
            elif type(first) == slice:
                # Setting a submatrix
                raise NotImplementedError
            else:
                # Setting a single element
                self._data[first][second] = value
        else:
            raise IndexError("invalid matrix index")
def __setitem__ ( self , i , value ) : if isinstance ( i , int ) : # Setting a row if len ( value ) != len ( self . _data [ i ] ) : raise ValueError ( "new value must have %d items" % self . _ncol ) self . _data [ i ] = list ( value ) elif isinstance ( i , slice ) : # Setting multiple rows if len ( value ) != len ( self . _data [ i ] ) : raise ValueError ( "new value must have %d items" % self . _ncol ) if any ( len ( row ) != self . _ncol for row in value ) : raise ValueError ( "rows of new value must have %d items" % self . _ncol ) self . _data [ i ] = [ list ( row ) for row in value ] elif isinstance ( i , tuple ) : try : first = i [ 0 ] except IndexError : first = slice ( None ) try : second = i [ 1 ] except IndexError : second = slice ( None ) if type ( first ) == slice and type ( second ) == slice : # Setting a submatrix # TODO raise NotImplementedError elif type ( first ) == slice : # Setting a submatrix raise NotImplementedError else : # Setting a single element self . _data [ first ] [ second ] = value else : raise IndexError ( "invalid matrix index" )