def from_rows( Class, alphabet, rows ):
        """
        Create a new matrix for a sequence over alphabet `alphabet` taking 
        values from `rows` which is a list whose length is the width of the
        matrix, and whose elements are lists of values associated with each
        character (in the order those characters appear in alphabet). 
        """
        # Sorted alphabet
        sorted_alphabet = sorted( alphabet )
        # Character to index mapping (initialized to -1)
        char_to_index = zeros( (256), int16 ) - 1
        for i, ch  in enumerate( sorted_alphabet ):
            char_to_index[ ord(ch) ] = i
        # Array
        values = zeros( ( len( rows) , len( alphabet ) ), float32 )
        for i, row in enumerate( rows ):
            assert len( row ) == len( alphabet )
            for ch, val in zip( alphabet, row ):
                values[i, char_to_index[ord(ch)]] = val
        # Matrix
        matrix = Class()
        matrix.alphabet = alphabet
        matrix.sorted_alphabet = sorted_alphabet
        matrix.char_to_index = char_to_index
        matrix.values = values
        return matrix
def from_rows ( Class , alphabet , rows ) : sorted_alphabet = sorted ( alphabet ) char_to_index = zeros ( ( 256 ) , int16 ) - 1 for i , ch in enumerate ( sorted_alphabet ) : char_to_index [ ord ( ch ) ] = i values = zeros ( ( len ( rows ) , len ( alphabet ) ) , float32 ) for i , row in enumerate ( rows ) : assert len ( row ) == len ( alphabet ) for ch , val in zip ( alphabet , row ) : values [ i , char_to_index [ ord ( ch ) ] ] = val matrix = Class ( ) matrix . alphabet = alphabet matrix . sorted_alphabet = sorted_alphabet matrix . char_to_index = char_to_index matrix . values = values return matrix
Create a new matrix for a sequence over alphabet `alphabet` taking 
        values from `rows` which is a list whose length is the width of the
        matrix, and whose elements are lists of values associated with each
        character (in the order those characters appear in alphabet).