4 edited tags
| link
    Tweeted twitter.com/StackMma/status/1101089761228476417
3 added 15 characters in body
source | link

I have two arrays, say

array1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
array2 = {13, 4, 6, 20, 21};

I want to compare these two arrays by cycling array1array1 through all elements in array2array2. The output should be the position in each array where they match a condition, where the condition array2 = array1[n]-1array2[[m]] = array1[[n]]-1 is true. That is, the output should be:

output = {6,2}

Because in array2array2, 5-1 = 4$5-1 = 4$. (array1[6] = 5array1[[6]] = 5 and array2[2] = 4array2[[2]] = 4). So far, my code is

output = {Position[array1, #][[1, 1]], 
 Position[array2, #][[1, 1]]} & /@ (I have no idea)

Where the code on the left hand side of Map gives me the positions of a true condition. On the right hand side of Map, I'm not sure what to do.

To clarify a little bit, the code I want is similar to

output = {Position[array1, #][[1, 1]], 
Position[array2, #][[1, 1]]} & /@ Intersection[array1, array2]

Except I want the position of the element when array2 = array1-1array2 = array1-1 instead of when array1=array2array1 = array2.

I have two arrays, say

array1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
array2 = {13, 4, 6, 20, 21};

I want to compare these two arrays by cycling array1 through all elements in array2. The output should be the position in each array where they match a condition, where the condition array2 = array1[n]-1 is true. That is, the output should be:

output = {6,2}

Because in array2, 5-1 = 4. (array1[6] = 5 and array2[2] = 4). So far, my code is

output = {Position[array1, #][[1, 1]], 
 Position[array2, #][[1, 1]]} & /@ (I have no idea)

Where the code on the left hand side of Map gives me the positions of a true condition. On the right hand side of Map, I'm not sure what to do.

To clarify a little bit, the code I want is similar to

output = {Position[array1, #][[1, 1]], 
Position[array2, #][[1, 1]]} & /@ Intersection[array1, array2]

Except I want the position of the element when array2 = array1-1 instead of when array1=array2

I have two arrays, say

array1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
array2 = {13, 4, 6, 20, 21};

I want to compare these two arrays by cycling array1 through all elements in array2. The output should be the position in each array where they match a condition, where the condition array2[[m]] = array1[[n]]-1 is true. That is, the output should be:

output = {6,2}

Because in array2, $5-1 = 4$. (array1[[6]] = 5 and array2[[2]] = 4). So far, my code is

output = {Position[array1, #][[1, 1]], 
 Position[array2, #][[1, 1]]} & /@ (I have no idea)

Where the code on the left hand side of Map gives me the positions of a true condition. On the right hand side of Map, I'm not sure what to do.

To clarify a little bit, the code I want is similar to

output = {Position[array1, #][[1, 1]], 
Position[array2, #][[1, 1]]} & /@ Intersection[array1, array2]

Except I want the position of the element when array2 = array1-1 instead of when array1 = array2.

2 added 276 characters in body
source | link

I have two arrays, say

array1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
array2 = {13, 4, 6, 20, 21};

I want to compare these two arrays by cycling array1 through all elements in array2. The output should be the position in each array where they match a condition, where the condition array2 = array1[n]-1 is true. That is, the output should be:

output = {6,2}

Because in array2, 5-1 = 4. (array1[6] = 5 and array2[2] = 4). So far, my code is

output = {Position[array1, #][[1, 1]], 
 Position[array2, #][[1, 1]]} & /@ (I have no idea)

Where the code on the left hand side of Map gives me the positions of a true condition. On the right hand side of Map, I'm not sure what to do.

To clarify a little bit, the code I want is similar to

output = {Position[array1, #][[1, 1]], 
Position[array2, #][[1, 1]]} & /@ Intersection[array1, array2]

Except I want the position of the element when array2 = array1-1 instead of when array1=array2

I have two arrays, say

array1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
array2 = {13, 4, 6, 20, 21};

I want to compare these two arrays by cycling array1 through all elements in array2. The output should be the position in each array where they match a condition, where the condition array2 = array1[n]-1 is true. That is, the output should be:

output = {6,2}

Because in array2, 5-1 = 4. (array1[6] = 5 and array2[2] = 4). So far, my code is

output = {Position[array1, #][[1, 1]], 
 Position[array2, #][[1, 1]]} & /@ (I have no idea)

Where the code on the left hand side of Map gives me the positions of a true condition. On the right hand side of Map, I'm not sure what to do.

I have two arrays, say

array1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
array2 = {13, 4, 6, 20, 21};

I want to compare these two arrays by cycling array1 through all elements in array2. The output should be the position in each array where they match a condition, where the condition array2 = array1[n]-1 is true. That is, the output should be:

output = {6,2}

Because in array2, 5-1 = 4. (array1[6] = 5 and array2[2] = 4). So far, my code is

output = {Position[array1, #][[1, 1]], 
 Position[array2, #][[1, 1]]} & /@ (I have no idea)

Where the code on the left hand side of Map gives me the positions of a true condition. On the right hand side of Map, I'm not sure what to do.

To clarify a little bit, the code I want is similar to

output = {Position[array1, #][[1, 1]], 
Position[array2, #][[1, 1]]} & /@ Intersection[array1, array2]

Except I want the position of the element when array2 = array1-1 instead of when array1=array2

1
source | link