我如何在Julia中从数组中消除多行?

时间:2015-03-07 09:33:43

标签: arrays multidimensional-array julia

function prealloc()
    situation=zeros(Int64,3^5,5);
    i=1;
    for north=0:2, south=0:2, east=0:2, west=0:2, current=0:2
        situation[i,:]=[north, south, east, west, current]
        i+=1
    end
    situation
end
prealloc()

如何在Julia中从数组中删除多行?

1 个答案:

答案 0 :(得分:3)

您可以使用逻辑索引或整数索引。例如,

function eliminate_matching_rows(A, pattern)
    keep = [A[i,:] != pattern for i = 1:size(A,1)]
    A[keep, :]
end

将消除A中与pattern匹配的所有行。