Apr-30-2019, 12:40 PM

I am creating a matrix array by reading two different lists with for loop. But the second for loop stops after the first iteration.

The print output is only with one parameter *1 instead of the all other that are in the lists in the list f1.

The print output is only with one parameter *1 instead of the all other that are in the lists in the list f1.

import numpy as np f1 = [['N1M2', 'N1M3', 'N1M4', 'N1M5'], ['M1N2', 'N2M3', 'N2M4', 'N2M5'], ['N1M3', 'N1M4', 'N1M5', 'N2M3', 'N2M4', 'N2M5'], ['M1N3', 'M2N3', 'N3M4', 'N3M5'], ['N1M2', 'N1M4', 'N1M5', 'M2N3', 'N3M4', 'N3M5'], ['M1N2', 'M1N3', 'N2M4', 'N2M5', 'N3M4', 'N3M5'], ['N1M4', 'N1M5', 'N2M4', 'N2M5', 'N3M4', 'N3M5'], ['M1N4', 'M2N4', 'M3N4', 'N4M5'], ['N1M2', 'N1M3', 'N1M5', 'M2N4', 'M3N4', 'N4M5'], ['M1N2', 'M1N4', 'N2M3', 'N2M5', 'M3N4', 'N4M5'], ['N1M3', 'N1M5', 'N2M3', 'N2M5', 'M3N4', 'N4M5'], ['M1N3', 'M1N4', 'M2N3', 'M2N4', 'N3M5', 'N4M5'], ['N1M2', 'N1M5', 'M2N3', 'M2N4', 'N3M5', 'N4M5'], ['M1N2', 'M1N2', 'M1N3', 'N2M5', 'N3M5', 'N4M5'], ['N1M5', 'N2M5', 'N3M5', 'N4M5'], ['M1N5', 'M2N5', 'M3N5', 'M4N5'], ['N1M2', 'N1M3', 'N1M4', 'M2N5', 'M3N5', 'M4N5'], ['M1N2', 'M1N5', 'N2M3', 'N2M4', 'M3N5', 'M4N5'], ['N1M3', 'N1M4', 'N2M3', 'N2M4', 'M3N5', 'M4N5'], ['M1N3', 'M1N5', 'M2N3', 'M2N5', 'N3M4', 'M4N5'], ['N1M2', 'N1M4', 'M2N3', 'M2N5', 'N3M4', 'M4N5'], ['M1N2', 'M1N3', 'M1N5', 'N2M4', 'N3M4', 'M4N5'], ['N1M4', 'N2M4', 'N3M4', 'M4N5'], ['M1N4', 'M1N5', 'M2N4', 'M2N5', 'M3N4', 'M3N5'], ['N1M2', 'N1M3', 'M2N4', 'M2N5', 'M3N4', 'M3N5'], ['M1N2', 'M1N4', 'M1N5', 'N2M3', 'M3N4', 'M3N5'], ['N1M3', 'N2M3', 'M3N4', 'M3N5'], ['M1N3', 'M1N4', 'M1N5', 'M2N3', 'M2N4', 'M2N5'], ['N1M2', 'M2N3', 'M2N4', 'M2N5'], ['M1N2', 'M1N3', 'M1N4', 'M1N5']] f2 = ['M1N2','M1N3','M1N4','M1N5','M2N3','M2N4','M2N5','M3N4','M3N5','M4N5','N1M2','N1M3','N1M4','N1M5','N2M3','N2M4','N2M5','N3M4','N3M5','N4M5'] def get_matrix(f1, f2): new = [] for j in f1: for x in j: for i in f2: if i == x: new.append('%s*1' % i) #new.append('0') else: new.append('%s*0' % i) #new.append('1') break new1 = np.array(new) shape = ( 30, 20 ) new1.reshape( shape ) return new1.reshape( shape ) print (get_matrix(f1, f2))

```
Output:
[['M1N2*0' 'M1N3*0' 'M1N4*0' 'M1N5*0' 'M2N3*0' 'M2N4*0' 'M2N5*0' 'M3N4*0'
'M3N5*0' 'M4N5*0' 'N1M2*1' 'N1M3*0' 'N1M4*0' 'N1M5*0' 'N2M3*0' 'N2M4*0'
'N2M5*0' 'N3M4*0' 'N3M5*0' 'N4M5*0']
['M1N2*1' 'M1N3*0' 'M1N4*0' 'M1N5*0' 'M2N3*0' 'M2N4*0' 'M2N5*0' 'M3N4*0'
'M3N5*0' 'M4N5*0' 'N1M2*0' 'N1M3*0' 'N1M4*0' 'N1M5*0' 'N2M3*0' 'N2M4*0'
'N2M5*0' 'N3M4*0' 'N3M5*0' 'N4M5*0']
['M1N2*0' 'M1N3*0' 'M1N4*0' 'M1N5*0' 'M2N3*0' 'M2N4*0' 'M2N5*0' 'M3N4*0'
'M3N5*0' 'M4N5*0' 'N1M2*0' 'N1M3*1' 'N1M4*0' 'N1M5*0' 'N2M3*0' 'N2M4*0'
'N2M5*0' 'N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