[Haskell-cafe] Matlab Style Logic Operations ala V1.*(V2>0) on Vectors and Matrices with HMatrix ??
aruiz at um.es
Tue Dec 21 13:38:04 CET 2010
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):
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
11 |> [0.0,0.0,0.0,0.0,0.0,0.0,16.0,17.0,18.0,19.0,20.0]
> . -- Many thanks in advance Phil
More information about the Haskell-Cafe