我正在尝试解决以下问题:
'''
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()?有什么区别?