Matix index operations in CUDA

Hello.
if someone had a similar problem, I would like to know how to copy one array into another but on such way that values in another matrix represent the index of a first matrix elements?
If you don’t understand what am I talking about look at the picture:

OK, guys, I solved this in C, but know I have the similar problem on CUDA device.

I need to do this:

This is my code. Only thing what is missing is index in first braces.

__global__ void MeanShiftCalc(int *input, int *moment_x_d, int *moment_y_d, int *masa_x_d, int *masa_y_d){

	int tx=threadIdx.x;

	int ty=threadIdx.y;

		for(int i=0;i<a_a;i++){

			moment_x_d[]+=(i+1)*input[ty*a_a+i];

			masa_x_d[]+=input[ty*a_a+i];

	

			moment_y_d[]+=(i+1)*input[i*a_a+tx];

			masa_y_d[]+=input[i*a_a+tx];

		}

}

Help!

OK, guys, I solved this in C, but know I have the similar problem on CUDA device.

I need to do this:

This is my code. Only thing what is missing is index in first braces.

__global__ void MeanShiftCalc(int *input, int *moment_x_d, int *moment_y_d, int *masa_x_d, int *masa_y_d){

	int tx=threadIdx.x;

	int ty=threadIdx.y;

		for(int i=0;i<a_a;i++){

			moment_x_d[]+=(i+1)*input[ty*a_a+i];

			masa_x_d[]+=input[ty*a_a+i];

	

			moment_y_d[]+=(i+1)*input[i*a_a+tx];

			masa_y_d[]+=input[i*a_a+tx];

		}

}

Help!

Solved it, just have to write ty in misssing position!

Solved it, just have to write ty in misssing position!