I use two for loop to go through two arrays. I have set the conditions to print me only those that meet my conditions.
the individual positions in are in the array comb_x and comb_y. this results in conditions in the for loop
This is fine and works as it should.
This my code
import os
import numpy as np
from itertools import combinations
a=np.array([0, 0, 0, 1, 1, 1, 2, 2, 2])
b=np.array([0, 1, 2, 0, 1, 2, 0, 1, 2])
z1=np.array([1, 1])
z2=np.array([1, 1])
comb_x=np.array([0, 0, 1, 1])
comb_y=np.array([0, 1, 0, 1])
for (j), (k) in zip(a,b):
z1[:]=0
z1[:j]=1
x12=z1
z2[:]=0
z2[:k]=1
y12=z2
#print(x12,y12)
for (h),(n),(r) in zip(comb_x,comb_y,np.arange(0,4)):
if x12[h]==1 and y12[n]==1:
print('pravda',x12,y12)
My output sorts those numbers by values
my output:
[1 0] [1 0]
[1 0] [1 1]
[1 0] [1 1]
[1 1] [1 0]
[1 1] [1 0]
[1 1] [1 1]
[1 1] [1 1]
[1 1] [1 1]
[1 1] [1 1]
I need them to appear as well as follow in each iteration
required output
[1 0] [1 0]
[1 0] [1 1]
[1 1] [1 0]
[1 1] [1 1]
[1 0] [1 1]
[1 1] [1 1]
[1 1] [1 0]
[1 1] [1 1]
[1 1] [1 1]
To make it easier to see, I'll show below what the individual iterations and their results should look like
first iteration:
[1 0] [1 0]
[1 0] [1 1]
[1 1] [1 0]
[1 1] [1 1]
second iteration:
[1 0] [1 1]
[1 1] [1 1]
third iteration:
[1 1] [1 0]
[1 1] [1 1]
fourth iteration:
[1 1] [1 1]
But as you can see, it does not save them by iteration, but sorts them in ascending order by value
Could it be arranged according to iterations so that it is still a numpy array?