[英]In python, is “args = [temp[n] for n in array(index)]” doing a check of temp[n]?
我正在从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
在哪种情况下,“ this.scratch [c]”检查数据是否与“ this.connections(n)”中的c相匹配?
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);
}
我认为您正在反向看它。
# Python:
args = [f(x) for x in iter]
类似于
// Java:
List<Type> args = new ArrayList<Type>(iter.size());
for (Type x : iter)
args.add(f(x));
因此,在[f(x) for x in iter]
,将x
分配给iter
每个元素,对f(x)
进行求值,并将结果收集在一个列表中。
[a for b in c]
是列表推导。 它通过遍历列表(或其他可迭代) c
中的每个元素来生成一个列表,调用该元素b
,然后计算表达式a
并将结果放入结果列表中。
这个:
args = [this.scrath[c] for c in this.connections(n)]
等效于此:
args = []
for c in this.connections(n):
args.append(this.scrath[c])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.