Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find() doesn't support multiple conditions #6851

Closed
milktrader opened this issue May 15, 2014 · 8 comments
Closed

find() doesn't support multiple conditions #6851

milktrader opened this issue May 15, 2014 · 8 comments

Comments

@milktrader
Copy link
Contributor

julia> a = [1:10];

julia> find(a .> 5)
5-element Array{Int64,1}:
  6
  7
  8
  9
 10

julia> find(a .> 5 & a .< 9)
7-element Array{Int64,1}:
  2
  3
  6
  7
  8
  9
 10

julia> find(a .< 9 & a .> 5)
0-element Array{Int64,1}
@milktrader
Copy link
Contributor Author

#4127

@jiahao
Copy link
Member

jiahao commented May 15, 2014

I think this is an operator precedence issue:

julia> find((a.>5) & (a .<9))
3-element Array{Int64,1}:
 6
 7
 8

julia> find (5.<a.<9)
3-element Array{Int64,1}:
 6
 7
 8

@milktrader
Copy link
Contributor Author

Oh, cool. I'm not sure if matlab behaves this way but I'm glad we have this available. Thanks!

@ViralBShah
Copy link
Member

What would be great is if find can take an expression and evaluate it over the input, instead of forming the intermediate temporary array.

@rickhg12hs
Copy link
Contributor

@ViralBShah : You mean like: ???

julia> a=[1:10]
10-element Array{Int32,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10

julia> a[(a.<9)&(a.>5)]
3-element Array{Int32,1}:
 6
 7
 8

@ViralBShah
Copy link
Member

This creates several temporaries too under the hood.

@rickhg12hs
Copy link
Contributor

@ViralBShah There's still a lot of mystery under the bonnet for me. How does filter fit in-the-mix here?

@mbauman
Copy link
Member

mbauman commented May 15, 2014

This is #5187. I've been thinking I'd bump it at the start of the .4 cycle and champion it a bit more loudly. I'd really like to be able to write multiple conditions without parentheses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants