java - 在Python中, "args = [temp[n] for n in array(index)]"是否在检查temp[n]?

标签 java python for-loop

我正在从 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);
}

最佳答案

[a for b in c] 是列表理解。它通过遍历列表(或其他可迭代)中的每个元素 c 来生成列表,调用该元素 b,然后计算表达式 a并将结果放入结果列表中。

关于java - 在Python中, "args = [temp[n] for n in array(index)]"是否在检查temp[n]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17974655/

相关文章:

java - 从数据库中搜索数据在java中没有搜索到该术语?

java - 如何禁用 ImageView 中的图像拉伸(stretch)?

java - Apache tomcat 8.0 服务器无法编译 jsps

java - 远程调试linux机器intellij

Python 3字节在CGI脚本中使用非ascii字符进行解码

python - Cuda组合算法错误: CUDA_ERROR_LAUNCH_FAILED

python - [ orth , pos , tag , lema 和 text ] 的 spaCy 文档

javascript - 如何从 javascript 中的子函数返回值

for-loop - delims 中的双引号=?

java - 数组大小不确定的写入循环