我正在从Python转换成Java。你知道吗
我的问题是“args”在做什么?你知道吗
args = [this.scrath[c] for c in this.connections(n)]; //Python
是不是:
[this.scrath[c] //get data at index c of this.scratch[]
for c in // for number of c in connections
this.connections(n)]; //connections to ANN_Neuron n
在这种情况下这个。刮痕[c] “检查数据是否与中的c匹配”这个。连接(n) “?你知道吗
this.scratch = Arrays.copyOfRange(inputValues, this.scratch.length-this.input_length, this.scratch.length+1); //JAVA
//inputValues given as negative values.
for (int i=0; i<this.scratch.length; i++){
this.scratch[i] = inputValues[i]*-1;
}
//loop through the active genes in order
for (ANN_Neuron n : nodes){
if (n.active){
float func = n.function;
for (ANN_Connection c : n.connections){
//Argument here!!
}
}
args = [this.scrath[c] for c in this.connections(n)]; //Python
//apply function to the inputs from scratch, save results in scratch
this.scratch[n] = function(*args);
}
这是:
相当于:
[a for b in c]
是一个列表理解。它通过遍历列表(或其他iterable)中的每个元素c
,调用该元素b
,然后计算表达式a
,并将结果放入结果列表中,从而生成一个列表。你知道吗我觉得你在向后看。你知道吗
类似于
所以在
[f(x) for x in iter]
中,将x
分配给iter
的每个元素,对f(x)
进行求值,并将结果收集到一个列表中。你知道吗相关问题 更多 >
编程相关推荐