@@ -68,7 +68,7 @@ def __init__(
6868 if init_value is not None and self .rows_labels and list (self .cols_labels ):
6969 mat = np .full ((len (self .rows_labels ), len (self .cols_labels )), init_value )
7070
71- elif not list ( mat ) :
71+ elif mat is None :
7272 raise ValueError ('A path matrix or initialization should be provided.' )
7373
7474 self .mat = np .array (mat )
@@ -114,7 +114,9 @@ def __next__(self):
114114
115115 nxt = tuple ()
116116 if len (self .rows_labels ) == 1 :
117- nxt += (self .mat [self .j ],)
117+ nxt += (self .mat [0 , self .j ],)
118+ elif len (self .cols_labels ) == 1 :
119+ nxt += (self .mat [self .i , 0 ],)
118120 else :
119121 nxt += (self .mat [self .i ][self .j ],)
120122
@@ -284,11 +286,21 @@ def delete_col_from_label(self, label):
284286
285287 def set_cell_from_labels (self , row_label , col_label , x ):
286288 """Set cell from labels."""
287- self .mat [self .rows_labels_ix_mapping [row_label ], self .cols_labels_ix_mapping [col_label ]] = x
289+ if len (self .rows_labels ) == 1 :
290+ self .mat [0 , self .cols_labels_ix_mapping [col_label ]] = x
291+ elif len (self .cols_labels ) == 1 :
292+ self .mat [self .rows_labels_ix_mapping [row_label ], 0 ] = x
293+ else :
294+ self .mat [self .rows_labels_ix_mapping [row_label ], self .cols_labels_ix_mapping [col_label ]] = x
288295
289296 def get_cell_from_labels (self , row_label , col_label ):
290297 """Get cell from labels."""
291- return self .mat [self .rows_labels_ix_mapping [row_label ], self .cols_labels_ix_mapping [col_label ]]
298+ if len (self .rows_labels ) == 1 :
299+ return self .mat [0 , self .cols_labels_ix_mapping [col_label ]]
300+ elif len (self .cols_labels ) == 1 :
301+ return self .mat [self .rows_labels_ix_mapping [row_label ], 0 ]
302+ else :
303+ return self .mat [self .rows_labels_ix_mapping [row_label ], self .cols_labels_ix_mapping [col_label ]]
292304
293305 """Methods"""
294306
0 commit comments