julia有没有find函数或者简单的用法

在matlab里面有find函数,可以查找数组里面的元素,julia里面有没有类似的内置函数?或者简单的用法

? 进入 help mode 输入 find 回车

help?> find
search: findmin findmax findall findprev findnext findmin! findmax! findlast findfirst

Couldn't find find
Perhaps you meant bind, sind, fill, fd, fld, Cint, asind, in, inv, min, rand, sin or sinc
  No documentation found.

  Binding find does not exist.

然后看看上面那几个 find 开头的函数是不是符合需求

哈,他就是没有find这个函数~~~

以前有,这大概也反映出来MATLAB的某些缺点吧。大家觉得这个find不够explicit,所以后来把名字改了,至于改成了啥,你在上面那些find开头的函数里找找就知道了。

我把文档给你复制过来了。。。

help?> findall
search: findall findmax! findmax findlast

findall(f::Function, A)

Return a vector I of the indices or keys of A where f(A[I]) returns true. If there are
no such elements of A, return an empty array.

Indices or keys are of the same type as those returned by keys(A) and pairs(A).

Examples
≡≡≡≡≡≡≡≡≡≡

julia> x = [1, 3, 4]
3-element Array{Int64,1}:
1
3
4

julia> findall(isodd, x)
2-element Array{Int64,1}:
1
2

julia> A = [1 2 0; 3 4 0]
2×3 Array{Int64,2}:
1 2 0
3 4 0
julia> findall(isodd, A)
2-element Array{CartesianIndex{2},1}:
CartesianIndex(1, 1)
CartesianIndex(2, 1)

julia> findall(!iszero, A)
4-element Array{CartesianIndex{2},1}:
CartesianIndex(1, 1)
CartesianIndex(2, 1)
CartesianIndex(1, 2)
CartesianIndex(2, 2)

julia> d = Dict(:A => 10, :B => -1, :C => 0)
Dict{Symbol,Int64} with 3 entries:
:A => 10
:B => -1
:C => 0

julia> findall(x → x >= 0, d)
2-element Array{Symbol,1}:
:A
:C

──────────────────────────────────────────────────────────────────────────────────────

findall(A)

Return a vector I of the true indices or keys of A. If there are no such elements of
A, return an empty array. To search for other kinds of values, pass a predicate as the
first argument.

Indices or keys are of the same type as those returned by keys(A) and pairs(A).

Examples
≡≡≡≡≡≡≡≡≡≡

julia> A = [true, false, false, true]
4-element Array{Bool,1}:
true
false
false
true

julia> findall(A)
2-element Array{Int64,1}:
1
4

julia> A = [true false; false true]
2×2 Array{Bool,2}:
true false
false true

julia> findall(A)
2-element Array{CartesianIndex{2},1}:
CartesianIndex(1, 1)
CartesianIndex(2, 2)

julia> findall(falses(3))
0-element Array{Int64,1}

PS. CartesianIndex 这个类型正是Julia好用的地方

QQ%E5%9B%BE%E7%89%8720180813232354 已经得到初步解决了,这是我写的代码

你想干啥…没看懂。如果是想获得index

i1, i2 = findfirst(b)

就可以获得单独的,整体肯定是 CartesianIndex

感觉查找条件可以写成lambda的样子,毕竟本质上这里的 b 就是lambda……

julia> a=[1 3 5 6]

1×4 Array{Int64,2}:
 1  3  5  6

julia> findall(it->it == 3, a)
1-element Array{CartesianIndex{2},1}:
 CartesianIndex(1, 2)
1 个赞

我觉得他可能在问X,Y问题
建议大佬可以在置顶的帖子加一条, 帮助大家避免这类问题.

QQ%E5%9B%BE%E7%89%8720180813234043
现在查找和索引是会了些了,呵呵

QQ%E5%9B%BE%E7%89%8720180814115419
终于搞清楚怎么获取数字坐标了,列向量返回的坐标索引index是数字

QQ%E5%9B%BE%E7%89%8720180816000930
这样更简洁,但是1.0版本可以使用此函数,0.6.4版本是不行的。