Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 First for loop stops after first iteration
#1
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.


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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N5*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' 'N3M4*0' 'N3M5*0' 'N4M5*0'] ['M1N2*0' 'M1N3*1' '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*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']]
Quote
#2
because you have break on line 17
Quote
#3
(Apr-30-2019, 12:42 PM)buran Wrote: break
without the break statement the output is the following one
Output:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-170-4c6aef3bebbf> in <module> 16 return new1.reshape( shape ) 17 ---> 18 print (get_matrix(f1, f2)) <ipython-input-170-4c6aef3bebbf> in get_matrix(f1, f2) 13 new1 = np.array(new) 14 shape = ( 30, 20 ) ---> 15 new1.reshape( shape ) 16 return new1.reshape( shape ) 17 ValueError: cannot reshape array of size 3200 into shape (30,20)
Quote
#4
what shape do you want? 30x20 does not work
Quote
#5
(Apr-30-2019, 01:41 PM)buran Wrote: what shape do you want? 30x20 does not work

Yes it should be 30x20.
But I can simplify the example. The point is to create new lists that for the elements in f1 will *1 and for the missing elements comparing to f2 will add *0.

f1 = [['N1M2', 'N1M3', 'N1M4', 'N1M5'], ['M1N2', 'N2M3', 'N2M4', 'N2M5'], ['N1M3', 'N1M4', 'N1M5', 'N2M3', 'N2M4', 'N2M5']]

f2 = ['M1N2','M1N3','M1N4','M1N5','M2N3','M2N4','M2N5','M3N4','M3N5','M4N5','N1M2','N1M3','N1M4','N1M5','N2M3','N2M4','N2M5','N3M4','N3M5','N4M5']
I don't know how I can loop correctly to solve this problem.
Quote
#6
30X20 would be 600 elements and you have 3200 (160x20). When you are reshaping, the total number of elements can’t be altered. That is why it works with break - f1 has 30 sub-lists and with brake it takes first element of each so you get 30x20 array to reshape
with the simplified example would you share what desired output would be and how it is achieved
Quote
#7
(Apr-30-2019, 04:34 PM)buran Wrote: 30X20 would be 600 elements and you have 3200 (160x20). When you are reshaping, the total number of elements can’t be altered. That is why it works with break - f1 has 30 sub-lists and with brake it takes first element of each so you get 30x20 array to reshape
with the simplified example would you share what desired output would be and how it is achieved

f1 = [['N1M2', 'N1M3', 'N1M4', 'N1M5']]

f2 = ['M1N2','M1N3','M1N4','M1N5','M2N3','M2N4','M2N5','M3N4','M3N5','M4N5','N1M2','N1M3','N1M4','N1M5','N2M3','N2M4','N2M5','N3M4','N3M5','N4M5']
new = []
def get(f1, f2):
    for j in f1:
        for x in j:
            for i in f2:
                if i == x:
                    new.append('%s*1' % i)
                else:
                    new.append('%s*0' % i)
    return new
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*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', '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*0', 'N1M4*1', '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*0', 'N1M4*0', 'N1M5*1', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0']
but the desired output is:
Output:
['M1N2*0', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*1', 'N1M3*1', 'N1M4*1', 'N1M5*1', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0']
How could I get this?
Quote
#8
still not sure I understand, but this will produce the desired result. requires python 3.6+

f1 = [['N1M2', 'N1M3', 'N1M4', 'N1M5']]
 
f2 = ['M1N2','M1N3','M1N4','M1N5','M2N3','M2N4','M2N5','M3N4','M3N5','M4N5','N1M2','N1M3','N1M4','N1M5','N2M3','N2M4','N2M5','N3M4','N3M5','N4M5']

new = []
for item in f2:
    for sub_list in f1:
        new_item = f'{item}*{int(item in sub_list)}'
        new.append(new_item)
print(new)
Quote
#9
(May-01-2019, 02:10 PM)buran Wrote: still not sure I understand, but this will produce the desired result. requires python 3.6+
f1 = [['N1M2', 'N1M3', 'N1M4', 'N1M5']] f2 = ['M1N2','M1N3','M1N4','M1N5','M2N3','M2N4','M2N5','M3N4','M3N5','M4N5','N1M2','N1M3','N1M4','N1M5','N2M3','N2M4','N2M5','N3M4','N3M5','N4M5'] new = [] for item in f2: for sub_list in f1: new_item = f'{item}*{int(item in sub_list)}' new.append(new_item) print(new)

Thank you very much, but in case with two lists in f1
f1 = [['N1M2', 'N1M3', 'N1M4', 'N1M5'], ['M1N2', 'N2M3', 'N2M4', 'N2M5']]
f2 = ['M1N2','M1N3','M1N4','M1N5','M2N3','M2N4','M2N5','M3N4','M3N5','M4N5','N1M2','N1M3','N1M4','N1M5','N2M3','N2M4','N2M5','N3M4','N3M5','N4M5']
 
new = []
for item in f2:
    for sub_list in f1:
        new_item = f'{item}*{int(item in sub_list)}'
        new.append(new_item)
print(new)
It will give the output:
Output:
['M1N2*0', 'M1N2*1', 'M1N3*0', 'M1N3*0', 'M1N4*0', 'M1N4*0', 'M1N5*0', 'M1N5*0', 'M2N3*0', 'M2N3*0', 'M2N4*0', 'M2N4*0', 'M2N5*0', 'M2N5*0', 'M3N4*0', 'M3N4*0', 'M3N5*0', 'M3N5*0', 'M4N5*0', 'M4N5*0', 'N1M2*1', 'N1M2*0', 'N1M3*1', 'N1M3*0', 'N1M4*1', 'N1M4*0', 'N1M5*1', 'N1M5*0', 'N2M3*0', 'N2M3*1', 'N2M4*0', 'N2M4*1', 'N2M5*0', 'N2M5*1', 'N3M4*0', 'N3M4*0', 'N3M5*0', 'N3M5*0', 'N4M5*0', 'N4M5*0']
But I need this output:
Output:
['M1N2*0', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*1', 'N1M3*1', 'N1M4*1', 'N1M5*1', '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*1', 'N2M4*1', 'N2M5*1', 'N3M4*0', 'N3M5*0', 'N4M5*0']
Quote
#10
(May-01-2019, 03:01 PM)Divanova94 Wrote: [quote="buran" pid="79039" dateline="1556719854"]still not sure I understand, but this will produce the desired result. requires python 3.6+
f1 = [['N1M2', 'N1M3', 'N1M4', 'N1M5']] f2 = ['M1N2','M1N3','M1N4','M1N5','M2N3','M2N4','M2N5','M3N4','M3N5','M4N5','N1M2','N1M3','N1M4','N1M5','N2M3','N2M4','N2M5','N3M4','N3M5','N4M5'] new = [] for item in f2: for sub_list in f1: new_item = f'{item}*{int(item in sub_list)}' new.append(new_item) print(new)
Thank you very much, It worked :)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Parallel iteration with for loop Josh_Python890 1 171 Jul-19-2019, 11:50 PM
Last Post: metulburr
  Multiprocessing my Loop/Iteration (Try...Except) Jompie96 7 299 Jun-19-2019, 12:59 PM
Last Post: noisefloor
  file.write stops while true loop from executing in python3 boonr 3 348 Mar-25-2019, 12:50 PM
Last Post: ichabod801
  Python Thread stops execution neethuvp 1 315 Feb-18-2019, 06:36 PM
Last Post: micseydel
  randint stops changing values in a loop Naito 4 460 Jan-30-2019, 08:15 AM
Last Post: perfringo
  issue with updating list every iteration of a loop ftrillaudp 2 423 Oct-29-2018, 03:23 AM
Last Post: ftrillaudp
  exception during iteration loop Skaperen 6 606 Oct-24-2018, 12:35 AM
Last Post: Skaperen
  detect when scanner stops darter 1 496 Jun-29-2018, 10:07 PM
Last Post: Larz60+
  My code prints out my string 5 times and then just stops? Abstract_Otaku 0 426 Jun-13-2018, 07:11 PM
Last Post: Abstract_Otaku
  Looping issue, stops working JohnOsis 7 979 Apr-05-2018, 09:20 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)