Your question, your audience. Choose who sees your identityâ€”and your questionâ€”with question security.

I have an array updated every second. For practical needs I need to save last 20 values in double array with permanent shifting values from 0 to 19.

Incoming data:

Avg[0] = (openBid[0] + openAsk[0])/2;

After it has to be converted in double array:

Avg[0] = X[0][0];

and then, when new value arrive into X[0][0], value of X[0][0] has to be shifted into the X[0][1];

after each new arriving all values have to be shifted down up to X[0][19] and this process has to be endless (loop);

So, we will have permanently updated dynamic double array list of last 20 values of Avg[0].

Please advice sample of Java code which will shift values from one array member to another.

Incoming data:

Avg[0] = (openBid[0] + openAsk[0])/2;

After it has to be converted in double array:

Avg[0] = X[0][0];

and then, when new value arrive into X[0][0], value of X[0][0] has to be shifted into the X[0][1];

after each new arriving all values have to be shifted down up to X[0][19] and this process has to be endless (loop);

So, we will have permanently updated dynamic double array list of last 20 values of Avg[0].

Please advice sample of Java code which will shift values from one array member to another.

There's no real need to check how many need to be shifted, you just shift all of them every time. If there is junk, it just gets shifted around and no one gets hurt.

Technically I'd use a circular queue for this, but if you don't have any idea what I'm talking about, just use the for loop and it will work just fine.

http://stackoverflow.com/questions/590069/how-would-you-code-an-efficient-circular-buffer-in-java-or-c

```
double[][] X;
........
X[0][i] = inX[0];
```

java.lang.NullPointerExcepat lionfx_algo.algobot.AlgoBo

so it will be:

X[0][0] => X[0][19]

X[1][0] => X[2][19]

X[2][0] => X[2][19]

only

X[0][0] => X[0][19]

just I show range which I need.

I tried different ways to transform single array list into double, but no success.

double X[3][20]

Then you'll have what you need. Three lists of 20 items.

When I get data from the table and send it to input of neural network it has to be single array because nn doesn't accept double.

But after this I have to create list of last 20 values for statistical calculations, for only this reason I try to transform single array into double.

I assume by that you mean into a two-dimensional array. You should probably use a circular queue of one-dimensional arrays

double bids[3]

double stats[3][20]

Use the first array for the values and the second for the statistical calculations.

A 3x20 array only contains 60 values total so you'd lose the original numbers.

Or if you define a circular queue class then do

double bids[3]

CircQueue stats[20]

Generally speaking, double stats[3][20] is extension of double bids[3], because we just add second array list to the first.

As I read in all tutorials about arrays - multidimensional array is just a set of few simple arrays.

One we already have, we need to get value from first array ant set it into second array list.

But bids[0] = stats[0][0]; not works because of different dimensions of arrays.

Lifetime of values bids[3] is one second, after this period all array has new values, so for statistical analysis we have only variables with last second value.

http://read.pudn.com/downloads9/sourcecode/internet/telnet/server/32411/Â¿Â¿Â¿Â¿Â¿Â¿/circQueue.java__.htm

but I still don't understand how it can help me for statistical data

Now you said you need the single array to use as input for your nn. Why not do this? Declare your array transposed (flipped) like this.

double X[20][3]

Then to shift, you just do X[19][0] = X[18][0] etc and let's say you want to pass the first set into your nn you just send it X[0] (X[0] will represent an array containing X[0][0], X[0][1], and X[0][2]). So X is your 2D array and X[0] is your 1D array. In this way you can actually pass any set of three values into the nn.

The reason everyone has suggested circular queues is because it is like the shifting array you described in the original post only it's much more efficient. But if you are only using an array of size 20, you won't see any speed improvement so if it's too complicated to mess with yet, don't bother.

```
int i;
double[] inX = new double[3];
double[][] X = new double [3][i];
..................
i = 20;
X[0][i] = inX[0];
for (int i = 19; i > 0; i--)
{
X[0][i] = X[0][i-1];
}
java.lang.ArrayIndexOutOfBoundsException: 20
```

About flipping array I didn't understand yet how I can set 20 values on it and how I can send 1D array data to nn?

Also about circular queues, can you advice how I can use it, I have already made this class, but I don't understand how to apply my array data on it?

Please advice

```
public class AlgoCalc {
int j;
double[][] X = new double[3][20];
public void algoCalc(double[] inX) {
for (int j = 19; j > 0; j--) {
X[0][j] = X[0][j - 1];
}
X[0][j] = inX[0];
X[1][j] = inX[1];
X[2][j] = inX[2];
System.out.println(" ixX[0] " + inX[0] + " : " + " inX[1] " + inX[1] + " : " + new java.util.Date());
System.out.println(" X[0][0] " + X[0][0] + " : " + " X[0][1] " + X[0][1] + " : " + " X[0][2] " + X[0][2] + " : " +
" X[0][3] " + X[0][3] + " : " + " X[0][4] " + X[0][4] + " : " + " X[0][5] " + X[0][5] + " : " +
" X[0][6] " + X[0][6] + " : " + " X[0][7] " + X[0][7] + " : " + " X[0][8] " + X[0][8] + " : " +
" X[0][9] " + X[0][9] + " : " + " X[0][10] " + X[0][10] + " : " + " X[0][11] " + X[0][11] + " : " +
" X[0][12] " + X[0][12] + " : " + " X[0][13] " + X[0][13] + " : " +" X[0][14] " + X[0][14] + " : " +
" X[0][15] " + X[0][15] + " : " + " X[0][16] " + X[0][16] + " : " + " X[0][17] " + X[0][17] + " : " +
" X[0][18] " + X[0][18] + " : " + " X[0][19] " + X[0][19] + " : " + new java.util.Date());
}
}
```

X[0][0] 0.06825125000000001 : X[0][1] 0.06825624999999999 : X[0][2] 0.06825775 : X[0][3] 0.06825775 : X[0][4] 0.06825775 : X[0][5] 0.06825775 : X[0][6] 0.06825775 : X[0][7] 0.06825574999999999 : X[0][8] 0.06825574999999999 : X[0][9] 0.06825975 : X[0][10] 0.06825975 : X[0][11] 0.06826375 : X[0][12] 0.06826375 : X[0][13] 0.06826125000000001 : X[0][14] 0.06826125000000001 : X[0][15] 0.06826125000000001 : X[0][16] 0.06826125000000001 : X[0][17] 0.06826125000000001 : X[0][18] 0.06826025 : X[0][19] 0.06826025 : Mon Nov 22 17:11:39 EET 2010
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

Open in new window