Find function in Julia 1.0.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?
julia
add a comment |
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
1
Very strong recommendation: transition via v0.7. In this case, v0.7 would have given you a deprecation warning telling you to usefindall
instead offind
. 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
add a comment |
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
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
julia
asked Nov 13 '18 at 15:08
A. A.A. A.
18012
18012
1
Very strong recommendation: transition via v0.7. In this case, v0.7 would have given you a deprecation warning telling you to usefindall
instead offind
. 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
add a comment |
1
Very strong recommendation: transition via v0.7. In this case, v0.7 would have given you a deprecation warning telling you to usefindall
instead offind
. 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
add a comment |
1 Answer
1
active
oldest
votes
Use filter()
:
julia> filter(x -> x<0, -5:5)
5-element ArrayInt64,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 ArrayInt64,1:
1
2
3
4
5
You can use getindex()
to get the actual values, e.g.:
julia> getindex(-5:5,indices)
5-element ArrayInt64,1:
-5
-4
-3
-2
-1
The last example can be also simply written as(-5:5)[indices]
orgetindex(-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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Use filter()
:
julia> filter(x -> x<0, -5:5)
5-element ArrayInt64,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 ArrayInt64,1:
1
2
3
4
5
You can use getindex()
to get the actual values, e.g.:
julia> getindex(-5:5,indices)
5-element ArrayInt64,1:
-5
-4
-3
-2
-1
The last example can be also simply written as(-5:5)[indices]
orgetindex(-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
add a comment |
Use filter()
:
julia> filter(x -> x<0, -5:5)
5-element ArrayInt64,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 ArrayInt64,1:
1
2
3
4
5
You can use getindex()
to get the actual values, e.g.:
julia> getindex(-5:5,indices)
5-element ArrayInt64,1:
-5
-4
-3
-2
-1
The last example can be also simply written as(-5:5)[indices]
orgetindex(-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
add a comment |
Use filter()
:
julia> filter(x -> x<0, -5:5)
5-element ArrayInt64,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 ArrayInt64,1:
1
2
3
4
5
You can use getindex()
to get the actual values, e.g.:
julia> getindex(-5:5,indices)
5-element ArrayInt64,1:
-5
-4
-3
-2
-1
Use filter()
:
julia> filter(x -> x<0, -5:5)
5-element ArrayInt64,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 ArrayInt64,1:
1
2
3
4
5
You can use getindex()
to get the actual values, e.g.:
julia> getindex(-5:5,indices)
5-element ArrayInt64,1:
-5
-4
-3
-2
-1
edited Nov 13 '18 at 15:45
answered Nov 13 '18 at 15:21
Przemyslaw SzufelPrzemyslaw Szufel
2,109212
2,109212
The last example can be also simply written as(-5:5)[indices]
orgetindex(-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
add a comment |
The last example can be also simply written as(-5:5)[indices]
orgetindex(-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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 offind
. 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