Incanter的新手,他想知道基于两个列表的成对乘积的结果创建矩阵的矢量化解决方案是什么样子。更清楚地说,我有两个我创建的列表
(def x (pdf-poisson (range 4) :lambda 2.2))
(def y (pdf-poisson (range 4) :lambda 1.5)).我现在想要一个4x4矩阵M,使得M(1,1)是x(1)和y(1)的乘积,M(1,2)是x(1)和y(2)的乘积,等等。
在Octave中使用外部产品很容易,所以希望Incanter也支持这一点。
我可以通过跨向量映射函数来轻松地手工编码,但如果可能的话,我想要一种惯用的或向量化的方法。
谢谢,JT
发布于 2011-12-24 03:58:10
刚刚在Incanter中找到了kronecker函数。向量的Kronecker积就是我需要的。所以
(kronecker y-poisson x-poisson)发布于 2011-12-22 09:13:03
以这个结尾:-
(def x-poisson (pdf-poisson (range 4) :lambda 2.2))
(def y-poisson (pdf-poisson (range 4) :lambda 1.5))
(defn- poisson-mapper
"Takes a list of values from the PDF, and returns a closure that will multiply each
value in the list by p. Used to create the probability matrix"
[p_list]
(fn [p] (map #(* p %) p_list)))
(def x-mapper (poisson-mapper x-poisson))
(def probabiliy-matix (matrix (map #(x-mapper %) y-poisson)))https://stackoverflow.com/questions/8595377
复制相似问题