(self, height=0, width=0, data=0)
Create a new matrix.
Create a new matrix.
Create a new matrix .
def __init__(self, height=0, width=0, data=0):
        """Create a new matrix."""
        self._height = height
        self._width = width
        if not width and not height:
            self._rows = [bytearray()]
        elif isinstance(data, int):
            self._rows = [bytearray([data])*width for _ in xrange(self._height)]
        else:
            # assume iterable, TypeError if not
            data = list(data)
            if len(data) == height:
                if isinstance(data[0], int):
                    # bytearrays and python3 bytes
                    self._rows = [bytearray([_row]) for _row in data]
                else:
                    assert len(data[0]) == width
                    self._rows = [bytearray(_row) for _row in data]
            else:
                assert len(data) == height * width
                self._rows = [
                    bytearray(data[_offs : _offs+width])
                    for _offs in xrange(0, len(data), width)
                ]
def __init__ ( self , height = 0 , width = 0 , data = 0 ) : self . _height = height self . _width = width if not width and not height : self . _rows = [ bytearray ( ) ] elif isinstance ( data , int ) : self . _rows = [ bytearray ( [ data ] ) * width for _ in xrange ( self . _height ) ] else : # assume iterable, TypeError if not data = list ( data ) if len ( data ) == height : if isinstance ( data [ 0 ] , int ) : # bytearrays and python3 bytes self . _rows = [ bytearray ( [ _row ] ) for _row in data ] else : assert len ( data [ 0 ] ) == width self . _rows = [ bytearray ( _row ) for _row in data ] else : assert len ( data ) == height * width self . _rows = [ bytearray ( data [ _offs : _offs + width ] ) for _offs in xrange ( 0 , len ( data ) , width ) ]