简体   繁体   中英

Why does an array change values of an another array accordingly?

I've been studying this code for a while. And I don't fully grasp how the var10000, which is attributed an existing array (like bias or weight), when is passed a new value, respectively changes the value in the attributed array. Is it just a java feature?

for(int layer = 1; layer < this.NETWORK_SIZE; ++layer) {
        for(int neuron = 0; neuron < this.NETWORK_LAYER_SIZES[layer]; ++neuron) {
            double delta = -eta * this.error_signal[layer][neuron];
            double[] var10000 = this.bias[layer];
            var10000[neuron] += delta;

            for(int prevNeuron = 0; prevNeuron < this.NETWORK_LAYER_SIZES[layer - 1]; ++prevNeuron) {
                var10000 = this.weights[layer][neuron];
                var10000[prevNeuron] += delta * this.output[layer - 1][prevNeuron];
            }
        }
    }

This sounds like you stumbled across one of the awesome but annoying parts of java.

Also, looking at the provided code, you are re-assigning the array in the for block, which would override its contents.

Good read: http://www.fredosaurus.com/notes-java/algorithms/copying/deep-shallow-copy.html

From site:

Assignment. The assignment operator (=) makes a copy of the "value". For a primitive type (int, double, etc) this simply copies the numeric value, but the assignment of a object copies only the reference (address in memory) of the object.

The curious thing is, it appears you are using the primative double, which should be a copy of the value: https://www.pearsonitcertification.com/articles/article.aspx?p=101368&seqNum=7

You can have arrays of any of the Java primitives or reference variables. The important point to remember is that when created, primitive arrays will have default values assigned, but object references will all be null.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM