Numpy,乘以3x10阵列的3x3阵列?

时间:2016-05-01 21:55:03

标签: python arrays numpy matrix

我有一个3x10矩阵(以numpy数组的形式),并希望将它乘以3x3变换矩阵。我不认为np.dot正在进行全矩阵乘法。有没有一种方法可以用数组进行这种乘法?

C9B531B60712E22D5C0892366E9C330555929A3C: no identity found
*** error: Couldn't codesign /Users/cherif/Apps/Parkisseo/NoPark/Build/Products/
Debug-iphoneos/NoPark.app/Frameworks/libswiftCoreLocation.dylib: 
codesign failed with exit code 1

是否存在执行整个矩阵乘法的点函数,而不仅仅是"For N dimensions it is a sum product over the last axis of a and the second-to-last of b"

2 个答案:

答案 0 :(得分:2)

您在transf的最后两个条目中缺少逗号。修复它们,你就会得到矩阵乘法:

# Missing commas between 0.75 and -0.1, 0.75 and -0.9.
transf = np.array([ [0.1, -0.4, 0],[0.9, 0.75 -0.1],[0.5, 0.75 -0.9] ])

# Fix with commas
transf = np.array([ [0.1, -0.4, 0],[0.9, 0.75, -0.1],[0.5, 0.75, -0.9]])

因为第一个数组实际上不是合法的二维数组,np.dot不能执行矩阵乘法。

答案 1 :(得分:1)

只需*运算符,但您需要定义matrix而不是array

import numpy as np
transf = np.matrix([ [1,2,3],[4,5,6],[1,2,3] ])     # 3x3 matrix
data = np.matrix([[2], [3], [4] ])      # 3x1 matrix

print transf * data

希望它有所帮助。