@@ -194,20 +194,15 @@ def _remove_useless_states(self):
194
194
195
195
"""
196
196
197
- # Indices of useless states.
198
- useless = []
199
-
200
- # Search for useless states.
201
- for i in range (self .states ):
202
- if (all (self .A [i , :]== zeros ((1 ,self .states )))and
203
- all (self .B [i , :]== zeros ((1 ,self .inputs )))):
204
- useless .append (i )
205
- # To avoid duplicate indices in useless, jump to the next
206
- # iteration.
207
- continue
208
- if (all (self .A [:,i ]== zeros ((self .states ,1 )))and
209
- all (self .C [:,i ]== zeros ((self .outputs ,1 )))):
210
- useless .append (i )
197
+ # Search for useless states and get the indices of these states
198
+ # as an array.
199
+ ax1_A = np .where (~ self .A .any (axis = 1 ))[0 ]
200
+ ax1_B = np .where (~ self .B .any (axis = 1 ))[0 ]
201
+ ax0_A = np .where (~ self .A .any (axis = 0 ))[1 ]
202
+ ax0_C = np .where (~ self .C .any (axis = 0 ))[1 ]
203
+ useless_1 = np .intersect1d (ax1_A ,ax1_B ,assume_unique = True )
204
+ useless_2 = np .intersect1d (ax0_A ,ax0_C ,assume_unique = True )
205
+ useless = np .union1d (useless_1 ,useless_2 )
211
206
212
207
# Remove the useless states.
213
208
self .A = delete (self .A ,useless ,0 )