在核心矩阵中的矩阵乘法 [英] matrix multiplication in core.matrix

查看:136
本文介绍了在核心矩阵中的矩阵乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个愚蠢的问题,但是我不能在一些环顾四周后找出来,所以我会问这里。

This seems like a silly question, but I can't figure this out after a bit of looking around, so I'll ask here.

我怎么能将3x2矩阵乘以core.matrix中的2x3矩阵?我必须误解一些非常基本的东西。天真的,我预计这将工作,我认为core.matrix将为我做基础的数学。

How can I multiply a 3x2 matrix by a 2x3 matrix in core.matrix? I must be misunderstanding something very basic. Naively, I expected this to work and I thought core.matrix would do the underlying math for me.

(* (matrix [[1 0 -2] 
            [0 3 -1]]) 
   (matrix [[0   3] 
            [-2 -1] 
            [0   4]]))

我通过google搜索找到了这个例子 http://www.purplemath.com/modules/mtrxmult.htm ,预期效果为

I found this example via first hit on a google search http://www.purplemath.com/modules/mtrxmult.htm and the expected result is

[[ 0 -5]
 [-6 -7]]

相反,我得到:

RuntimeException Incompatible shapes, cannot broadcast [3 2] to [2 3] 
clojure.core.matrix.impl.persistent-vector/eval5013/fn--5014 
(persistent_vector.clj:152)

提前感谢。

ps我的命名空间看起来就像来自core.matrix的示例

p.s. my namespace looks just like the example from core.matrix

(ns xyz
  (:refer-clojure :exclude [* - + == /]) ; get from core.matrix
  (:use clojure.core.matrix)
  (:use clojure.core.matrix.operators)
  (:gen-class))


推荐答案

* 矩阵运算符是元素级乘法 - 即,它强制两个操作数达到相同的维数,并产生一个新的矩阵,其中结果中每个位置的元素是该元素的乘积

The * matrix operator is an element-wise multiplication - that is, it forces the two operands to the same dimensions and produces a new matrix where the element at each position in the result is the product of the elements at that position in the operands.

我想你正在从查找 mmul clojure.core.matrix

I think you're looking for the mmul function from clojure.core.matrix.

这篇关于在核心矩阵中的矩阵乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆