【发布时间】:2020-12-01 23:59:20
【问题描述】:
我正在尝试在 Julia 中实现 Matlab 的 Find 功能。在Matlab中,代码是
find(A==0)
其中 A 是一个非常非常大的 n x m 矩阵,我在其中迭代和更新上述一系列大约 500 个步骤。在 Julia 中,我通过
[findall(x->x==0, D_tot)[j][2] for j in 1:count(x->x==0,D_tot)]
这似乎工作得很好,除了随着我的迭代进展它变得非常缓慢。例如,对于第一步,@time 产生
0.000432 seconds (33 allocations: 3.141 KiB)
第 25 步:
0.546958 seconds (40.37 k allocations: 389.997 MiB, 7.40% gc time)
第 65 步:
1.765892 seconds (86.73 k allocations: 1.516 GiB, 9.63% gc time)
在每一步中,A 的大小都保持不变,但变得更加复杂,而 Julia 似乎很难找到零点。有没有比我上面做的更好的方法来实现 Matlab 的“查找”功能?
【问题讨论】:
-
只写
findall(iszero, A)。你为什么要执行所有这些其他步骤?
标签: matlab search optimization find julia