Hi Phil,
On 12/20/2010 10:49 PM, gutti wrote:
>> Hi all,
>> In Matlab the following line of code:
> V3 = V1.*(V2>0)
>> (V2>0) gives a Bool-Vector with ones (trues) and zero's where elements
> of V2 are> 0; Then this Bool vector is used to multiply all elements in V1
> to zero
> where the condition V2>0 is not fulfilled.
>> How can I do that in Haskell ? (I haven't seen bol operations or mapping
> functions into vectors, arrays
> in the HMatrix.pdf).
Vectorized boolean operations are not yet implemented but I hope to get
them ready soon, including a "find" function. In the meantime you can
use zipVectorWith, as mentioned by Henning.
We could also use signum, but this is not recommended (signum 0 is 0):
import Numeric.LinearAlgebra
vec = fromList :: [Double] -> Vector Double
cond x = (signum (x-scalar eps) + 1 ) / 2
v1 = vec [10..20]
v2 = vec [-5..5]
v3 = v1 * cond v2
> v3
11 |> [0.0,0.0,0.0,0.0,0.0,0.0,16.0,17.0,18.0,19.0,20.0]
-Alberto
>> . -- Many thanks in advance Phil
>>>