Correlate vectors through the index and assign different values

0

I have the following vectors:

posicao_1 = [4, 62, 24, 18, 47, 62, 63, 78, 68, 87, 24, 18, 6, 8, 12, 17]

posicao_2 = [43, 61, 21, 19, 46, 63, 68, 72, 66, 89, 29, 10, 8, 7, 6, 15]

I need to look at the vector POSITION_1 the value [24, 18].

posicao_1 = [4, 62, **24, 18**, 47, 62, 63, 78, 68, 87, **24, 18**, 6, 8, 12, 17]

We can see that they are found in the indexes [2, 3] and [10, 11] of the POSITION_1 vector.

After locating these values, I need to go through the POSITION_2 vector and assign random and DIFFERENT values to the INDEXES [2, 3] and [10, 11] that I found in the POSITION_1 vector. For example:

You would have to assign random and DIFFERENT values:

posicao_2 = [43, 61, **22, 30**, 46, 63, 68, 72, 66, 89, **31, 41**, 8, 7, 6, 15]

I have the following script, which adds values EQUAL:

    ================================
    posicao_1 = [4, 62, 24, 18, 47, 62, 63, 78, 68, 87, 24, 18, 6, 8, 12, 17]
    posicao_2 = [43, 61, 21, 19, 46, 63, 68, 72, 66, 89, 29, 10, 8, 7, 6, 15]

    aleatorio = randrange(0, 100)

    pesq = [[24,18], [62,63]]

    for p in pesq:
        indices = [x for x in range(len(posicao_1)) if posicao_1[x:x+len(p)] == p ]

        for i in indices:
            posicao_2[i: i+len(p)] = [aleatorio] * len(p)

    print(posicao_2)        
    ==============================

How do I change to add DIFFERENT VALUES?

Could someone please help me?

Sorry, if it was not very clear, I tried to explain as much as possible!

    
asked by anonymous 12.08.2017 / 01:17

1 answer

1

If it is necessary that each "tuple" found be replaced by an equal random value in the two but different positions of the successive tuples, just generate a new random before each change:

for i in indices:
    aleatorio = random.randrange(0,100)
    posicao_2[i: i+len(p)] = [aleatorio] * len(p)
    
12.08.2017 / 11:17