Find function in Julia 1.0.2












2















I am transitioning to Julia 1.0.2 and I realized that the find function is not defined. In a previous version (Julia 0.6) I could write



find(x -> x<0, my_var)


In order to get the negative elements of the array called my_var. When I run the same code in Julia 1.0.2 I get the following error:



UndefVarError: find not defined


I couldn't find whether the find function is implemented under a different name or if it has been dropped. Is there any Julia 1.0.2 function that would be equivalent to the find function in previous Julia versions?










share|improve this question


















  • 1





    Very strong recommendation: transition via v0.7. In this case, v0.7 would have given you a deprecation warning telling you to use findall instead of find. Note, v0.7 is exactly the same as v1.0, but with deprecation warnings for thousands of little gotchas like this one.

    – Colin T Bowers
    Nov 13 '18 at 23:12
















2















I am transitioning to Julia 1.0.2 and I realized that the find function is not defined. In a previous version (Julia 0.6) I could write



find(x -> x<0, my_var)


In order to get the negative elements of the array called my_var. When I run the same code in Julia 1.0.2 I get the following error:



UndefVarError: find not defined


I couldn't find whether the find function is implemented under a different name or if it has been dropped. Is there any Julia 1.0.2 function that would be equivalent to the find function in previous Julia versions?










share|improve this question


















  • 1





    Very strong recommendation: transition via v0.7. In this case, v0.7 would have given you a deprecation warning telling you to use findall instead of find. Note, v0.7 is exactly the same as v1.0, but with deprecation warnings for thousands of little gotchas like this one.

    – Colin T Bowers
    Nov 13 '18 at 23:12














2












2








2








I am transitioning to Julia 1.0.2 and I realized that the find function is not defined. In a previous version (Julia 0.6) I could write



find(x -> x<0, my_var)


In order to get the negative elements of the array called my_var. When I run the same code in Julia 1.0.2 I get the following error:



UndefVarError: find not defined


I couldn't find whether the find function is implemented under a different name or if it has been dropped. Is there any Julia 1.0.2 function that would be equivalent to the find function in previous Julia versions?










share|improve this question














I am transitioning to Julia 1.0.2 and I realized that the find function is not defined. In a previous version (Julia 0.6) I could write



find(x -> x<0, my_var)


In order to get the negative elements of the array called my_var. When I run the same code in Julia 1.0.2 I get the following error:



UndefVarError: find not defined


I couldn't find whether the find function is implemented under a different name or if it has been dropped. Is there any Julia 1.0.2 function that would be equivalent to the find function in previous Julia versions?







julia-lang






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 15:08









A. A.A. A.

17512




17512








  • 1





    Very strong recommendation: transition via v0.7. In this case, v0.7 would have given you a deprecation warning telling you to use findall instead of find. Note, v0.7 is exactly the same as v1.0, but with deprecation warnings for thousands of little gotchas like this one.

    – Colin T Bowers
    Nov 13 '18 at 23:12














  • 1





    Very strong recommendation: transition via v0.7. In this case, v0.7 would have given you a deprecation warning telling you to use findall instead of find. Note, v0.7 is exactly the same as v1.0, but with deprecation warnings for thousands of little gotchas like this one.

    – Colin T Bowers
    Nov 13 '18 at 23:12








1




1





Very strong recommendation: transition via v0.7. In this case, v0.7 would have given you a deprecation warning telling you to use findall instead of find. Note, v0.7 is exactly the same as v1.0, but with deprecation warnings for thousands of little gotchas like this one.

– Colin T Bowers
Nov 13 '18 at 23:12





Very strong recommendation: transition via v0.7. In this case, v0.7 would have given you a deprecation warning telling you to use findall instead of find. Note, v0.7 is exactly the same as v1.0, but with deprecation warnings for thousands of little gotchas like this one.

– Colin T Bowers
Nov 13 '18 at 23:12












1 Answer
1






active

oldest

votes


















5














Use filter():



julia> filter(x -> x<0, -5:5)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1


Another option is to use findall() to get the indices of elements:



julia> indices = findall(x -> x<0, -5:5)
5-element Array{Int64,1}:
1
2
3
4
5


You can use getindex() to get the actual values, e.g.:



julia> getindex(-5:5,indices)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1





share|improve this answer


























  • The last example can be also simply written as (-5:5)[indices] or getindex(-5:5, indices) as broadcasting here is not needed.

    – Bogumił Kamiński
    Nov 13 '18 at 15:30











  • Thanks, that was exactly what I was looking for

    – A. A.
    Nov 13 '18 at 15:32











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283950%2ffind-function-in-julia-1-0-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














Use filter():



julia> filter(x -> x<0, -5:5)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1


Another option is to use findall() to get the indices of elements:



julia> indices = findall(x -> x<0, -5:5)
5-element Array{Int64,1}:
1
2
3
4
5


You can use getindex() to get the actual values, e.g.:



julia> getindex(-5:5,indices)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1





share|improve this answer


























  • The last example can be also simply written as (-5:5)[indices] or getindex(-5:5, indices) as broadcasting here is not needed.

    – Bogumił Kamiński
    Nov 13 '18 at 15:30











  • Thanks, that was exactly what I was looking for

    – A. A.
    Nov 13 '18 at 15:32
















5














Use filter():



julia> filter(x -> x<0, -5:5)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1


Another option is to use findall() to get the indices of elements:



julia> indices = findall(x -> x<0, -5:5)
5-element Array{Int64,1}:
1
2
3
4
5


You can use getindex() to get the actual values, e.g.:



julia> getindex(-5:5,indices)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1





share|improve this answer


























  • The last example can be also simply written as (-5:5)[indices] or getindex(-5:5, indices) as broadcasting here is not needed.

    – Bogumił Kamiński
    Nov 13 '18 at 15:30











  • Thanks, that was exactly what I was looking for

    – A. A.
    Nov 13 '18 at 15:32














5












5








5







Use filter():



julia> filter(x -> x<0, -5:5)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1


Another option is to use findall() to get the indices of elements:



julia> indices = findall(x -> x<0, -5:5)
5-element Array{Int64,1}:
1
2
3
4
5


You can use getindex() to get the actual values, e.g.:



julia> getindex(-5:5,indices)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1





share|improve this answer















Use filter():



julia> filter(x -> x<0, -5:5)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1


Another option is to use findall() to get the indices of elements:



julia> indices = findall(x -> x<0, -5:5)
5-element Array{Int64,1}:
1
2
3
4
5


You can use getindex() to get the actual values, e.g.:



julia> getindex(-5:5,indices)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 15:45

























answered Nov 13 '18 at 15:21









Przemyslaw SzufelPrzemyslaw Szufel

1,729111




1,729111













  • The last example can be also simply written as (-5:5)[indices] or getindex(-5:5, indices) as broadcasting here is not needed.

    – Bogumił Kamiński
    Nov 13 '18 at 15:30











  • Thanks, that was exactly what I was looking for

    – A. A.
    Nov 13 '18 at 15:32



















  • The last example can be also simply written as (-5:5)[indices] or getindex(-5:5, indices) as broadcasting here is not needed.

    – Bogumił Kamiński
    Nov 13 '18 at 15:30











  • Thanks, that was exactly what I was looking for

    – A. A.
    Nov 13 '18 at 15:32

















The last example can be also simply written as (-5:5)[indices] or getindex(-5:5, indices) as broadcasting here is not needed.

– Bogumił Kamiński
Nov 13 '18 at 15:30





The last example can be also simply written as (-5:5)[indices] or getindex(-5:5, indices) as broadcasting here is not needed.

– Bogumił Kamiński
Nov 13 '18 at 15:30













Thanks, that was exactly what I was looking for

– A. A.
Nov 13 '18 at 15:32





Thanks, that was exactly what I was looking for

– A. A.
Nov 13 '18 at 15:32


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283950%2ffind-function-in-julia-1-0-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation