【发布时间】:2015-12-04 16:03:11
【问题描述】:
我正在使用 Python 2.7、NumPy 1.6.2 和 SciPy 0.16.0 来计算以下内容。
我创建了一个 Hadamard 矩阵。我想从中获取一个向量并用它自己计算它的外积。这是我的代码。
from scipy import linalg
import numpy
from numpy import linalg as np
def test():
hadamard_matrix = linalg.hadamard(8)
outer_product_0 = numpy.multiply(hadamard_matrix[0], hadamard_matrix[0].transpose())
outer_product_1 = numpy.multiply(hadamard_matrix[0].transpose(), hadamard_matrix[0])
print str(outer_product_0)
print str(outer_product_1)
输出:
Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32
>>> import scipytest
>>> scipytest.test()
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
您可以看到,我得到的是一个向量,而不是一个 2X2 矩阵。我做错了吗?
【问题讨论】:
标签: python-2.7 numpy matrix scipy linear-algebra