简体   繁体   English

MATLAB中的大小等效函数在python中

[英]MATLAB Size equivalent function in python

hI i have a code in matlab. 我在matlab中有一个代码。 Based on my understanding I have translated that code to python. 根据我的理解,我已将该代码翻译为python。 Can someone let me know if it is the right way to translate. 有人可以告诉我这是否是正确的翻译方式。

for i = 1:length(Filters)
    Filters{i} = gpuArray(2*(single(sign(Filters{i}))-0.5));
    NumLearntWeightsEachLayer(i) = size(Filters{i},3)*size(Filters{i},4)*4;
end
NumLearntWeightsEachLayer(end) = size(Filters{end},3)*size(Filters{end},4);
NumLearntWeightsEachLayer
TotalLearntWeights = sum(NumLearntWeightsEachLayer)

Could someone let me know if this could be an equivalent code for the for loop here. 如果这可能是for循环的等效代码,有人可以告诉我。

for i in range (1,Filters):
    Filters(i) = (2* (Filters(i) - 0.5))
    NumLearntWeightsEachLayer(i) = (Filters(i),3).shape * (Filters(i),4).shape *4

I also want to know what could be the right translation for the last part of the code 我也想知道代码最后一部分的正确翻译是什么

 NumLearntWeightsEachLayer(end) = size(Filters{end},3)*size(Filters{end},4);

It's a good start.. some small fixes - 这是一个好的开始..一些小修复 -

for i in range (0,len(Filters)):
    for j in range(0, len(Filters[i]):
        Filters[i][j] = 2*(round(Filters[i][j],1) - 0.5)
    NumLearntWeightsEachLayer[i] = len(Filters[i][3])*len(Filters[i][4])*4

For the last line- 对于最后一行 -

NumLearntWeightsEachLayer(end) = size(Filters{end},3)*size(Filters{end},4);

It can be written as - 它可以写成 -

NumLearntWeightsEachLayer[-1] = len(Filters[-1][3])*len(Filters[-1][4]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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