if isinstance(matrix, dict):
self._matrix = np.full(( len(alphabet1), len(alphabet2) ), np.nan)
for key, value in matrix.items():
i = alphabet1.encode(key[0])
j = alphabet2.encode(key[1])
self._matrix[i,j] = value
elif isinstance(matrix, np.ndarray):
self._matrix = np.copy(matrix)
After Change
for j in range(len(alphabet2)):
sym1 = alphabet1.decode(i)
sym2 = alphabet2.decode(j)
try:
self._matrix[i,j] = matrix_dict[sym1, sym2]
except KeyError:
pass
elif isinstance(matrix, np.ndarray):
self._matrix = np.copy(matrix)
else:
raise TypeError("Matrix must be either a dictionary "