我有點麻煩numpy點產品 - 旋轉矩陣的產品&向量。請參閱代碼。這兩行應該給出相同的結果!在我存儲的地方,計算結果不應該影響計算。 Y應該和y1和y2一樣。Numpy不正確的點產品填充時
import numpy
rotMat = numpy.array([[-0.27514947, 0.40168313, 0.87346633], [ 0.87346633, -0.27514947, 0.40168313], [ 0.40168313, 0.87346633, -0.27514947]])
print "Rotation matrix:"
print rotMat
x = [1, 0, 1, 1, 1, 0]
X = numpy.array(x)
X.shape = (2, 3)
Y = numpy.array(6*[0])
Y.shape = (2, 3)
print "X", X
print "Y initialised:", Y
Y[0, :] = numpy.dot(rotMat, X[0, :])
Y[1, :] = numpy.dot(rotMat, X[1, :])
print "Filling Y initialised, Y=", Y
print "not filling Y initialised:"
print "y1", numpy.dot(rotMat, X[0, :])
print "y2", numpy.dot(rotMat, X[1, :])
其中給出結果:
Rotation matrix: [[-0.27514947 0.40168313 0.87346633]
[ 0.87346633 -0.27514947 0.40168313]
[ 0.40168313 0.87346633 -0.27514947]]
X [[1 0 1]
[1 1 0]]
Y initialised: [[0 0 0]
[0 0 0]]
Filling Y initialised, Y= [[0 1 0]
[0 0 1]]
not filling Y initialised:
y1 [ 0.59831686 1.27514946 0.12653366]
y2 [ 0.12653366 0.59831686 1.27514946]
我使用Python 2.7.11,與NumPy的1.10.1
那麼,有什麼麻煩?用更多細節解釋問題? – Divakar