Reputation: 119
I am trying to obtain only those columns of a matrix that satisfy two or more boolean conditions. More specifically, I am trying to find only those eigenvectors of a matrix based on certain constraints on the eigenvalues.
In python3.x I would do :
def get_special_vectors(A:np.ndarray,thresold1:float,thresold2:float) -> np.ndarray:
eigval, eigvec = np.linalg.eig(A)
eigvec = eigvec[:,np.array(eigval >= threshold1) & np.array(eigval <= thresold2)]
return eigvec
However in Julia, I am following this post but I seem to be messing up the AND (&) operator. I'm trying the following that results in a MethodError
:
eigvec = eigvec[:,vec(evalA .< 1.0) & vec(evalA .> 0)]
I'll be glad if someone can share any useful suggestions or any kind of help. Thanks in advance!
Upvotes: 3
Views: 56
Reputation: 1488
you should also broadcast the &
:
vec(evalA .< 1.0) .& vec(evalA .> 0)
I can't say for sure if it will solve your problem since you didn't give a complete example
You also might want to look at eachrow
and eachcol
Upvotes: 3
Reputation: 69879
You need to broadcast also &
so write .&
instead like this:
eigvec[:,vec(evalA .< 1.0) .& vec(evalA .> 0)]
however in this case the following should also just work:
eigvec[:,vec(0 .< evalA .< 1.0)]
(I do not see what evalA
is, so it is hard to tell if vec
is actually required in your code - I assume that it is required so I left it)
Upvotes: 2