[Haskell-cafe] Matlab Style Logic Operations ala V1.*(V2>0) on Vectors and Matrices with HMatrix ??
gutti
philipp.guttenberg at gmx.net
Wed Dec 22 23:09:11 CET 2010
Hi Henning,
You definitly caught me on that little Germanism :-)
About Your comments - a lot to learn and take in, but it really helps. -
Thanks a lot.
I just manged to get the Matrix masking running code looks like (code A see
below). Two quick questions:
question 1. u see the two commented lines I tried to get ur original line
running, but didn't know how to specify f
## Code ########
import Numeric.LinearAlgebra
import Graphics.Plot
matrix1 = fromLists [[0 .. 5],[30 .. 35],[50 .. 55]]
matrix2 = fromLists [[-1,2],[-3,4],[5,-6]]
-- matrix1 = buildMatrix 3 4 ( (r,c) -> fromIntegral r * fromIntegral c)
(3><4)
-- posPart v = mapVector (\a -> if a>=0 then a else 0) v
-- function2map a1 a2 = (\a1 a2 -> if a1>=0 then a2/a1 else a1/a2)
matrixfunction x y = liftMatrix2 (zipVectorWith(\a1 a2 -> if a2>=0 then a1
else 0)) x y
matrix3 = matrixfunction matrix1 matrix2
disp = putStr . disps 2
main = do
disp matrix1
disp matrix2
-- disp matrix3
mesh matrix1
#########
question 2: - the compiler comes up with some weired data type problem --
ghci has no problem this line :
matrixTest_Fail.hs:5:10:
Ambiguous type variable `t' in the constraints:
`Element t'
arising from a use of `fromLists' at matrixTest_Fail.hs:5:10-38
`Num t' arising from the literal `1' at matrixTest_Fail.hs:5:22
Possible cause: the monomorphism restriction applied to the following:
matrix2 :: Matrix t (bound at matrixTest_Fail.hs:5:0)
Probable fix: give these definition(s) an explicit type signature
or use -XNoMonomorphismRestriction
## Code #####
import Numeric.LinearAlgebra
import Graphics.Plot
matrix1 = fromLists [[1,2],[3,4],[5,6]]
matrix2 = fromLists [[1,2],[3,4],[5,6]]
disp = putStr . disps 2
main = do
disp matrix1
#########
--
View this message in context: http://haskell.1045720.n5.nabble.com/Matlab-Style-Logic-Operations-ala-V1-V2-0-on-Vectors-and-Matrices-with-HMatrix-tp3312601p3315761.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe
mailing list