我試圖解決以下問題:Python的矩陣內積
'''
Take in two matrices as numpy arrays, X and Y. Determine whether they have an inner product.
If they do not, return False. If they do, return the resultant matrix as a numpy array.
'''
用下面的代碼:
def mat_inner_product(X,Y):
if X.shape != Y.shape:
return False
else:
return np.inner(X,Y)
,我得到了以下錯誤消息:
.F
======================================================================
FAIL: test_mat_inner_product (test_methods.TestPython1)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/src/app/test_methods.py", line 27, in test_mat_inner_product
self.assertTrue(np.array_equal(result2, correct2))
AssertionError: False is not true
----------------------------------------------------------------------
Ran 2 tests in 0.001s
FAILED (failures=1)
什麼這是否意味着「錯誤是不正確的」?我有邏輯錯誤嗎?或者我應該使用.dot()而不是.inner()?有什麼不同?
這意味着你的函數返回了'False',但那是不正確的,你的函數應該返回'True'。 –
向我們展示測試代碼 – hpaulj
@hpaulj測試用例位於我無法訪問的場景後面 – Meruemu