psychopy.org | Reference | Downloads | Github

How to check if a specific row in one vector matches a row from another vector

What are you trying to achieve?:
Put simply, I have 2 vectors, called Vec1 and Vec2, each with 5 random values, e.g.:
Vec1 = [“S”,“Q”,“R”,“X”,“G”]
Vec2 = [“E”,“S”,“R”,“I”,“D”]

I want to check if the value in a specific row of a vector matches the same row in the other vector (in this example, I want to check if row 3 is identical for Vec1 and Vec2, and if so, I’ll print an error message as output).

What did you try to make it work?:
This code reads row 3 of each vector, and supposedly checks if they match (in this example, row 3 is the same because they both have “R”):

if Vec1[2] = Vec2[2]:
…print(‘ERROR: Duplication detected in row 3’)
else:
…print(‘No duplication in row 3’)

What specifically went wrong when you tried that?:
if Vec1[2] = Vec2[2]:
Syntax Error: Invalid Syntax

Hi @Ryan_Blything, the issue is that you are attempting to assign one list element to the other in your if statement. Instead, you need to use == to test for equality:

if vec1[2] == vec2[2]:  # Should be True or False