fork download
  1. import numpy as np
  2.  
  3. # Test Case 2: A(2,3,4) contract axes [1,2] with B(3,4,5) axes [0,1] → (2,5)
  4. A = np.array(list(range(1, 25)), dtype=np.float32).reshape(2, 3, 4, order='F')
  5. B = np.array(list(range(1, 61)), dtype=np.float32).reshape(3, 4, 5, order='F')
  6.  
  7. print("\nTest 2:")
  8. print("A shape:", A.shape)
  9. print("B shape:", B.shape)
  10.  
  11. result2 = np.tensordot(A, B, axes=([1, 2], [0, 1]))
  12.  
  13. print("\nResult shape:", result2.shape)
  14. print("Result:")
  15. print(result2)
  16. print("\nResult flattened (column-major):")
  17. print(result2.flatten(order='F'))
  18.  
Success #stdin #stdout 0.1s 23832KB
stdin
Standard input is empty
stdout
Test 2:
('A shape:', (2, 3, 4))
('B shape:', (3, 4, 5))
('\nResult shape:', (2, 5))
Result:
[[1222. 2950. 4678. 6406. 8134.]
 [1300. 3172. 5044. 6916. 8788.]]

Result flattened (column-major):
[1222. 1300. 2950. 3172. 4678. 5044. 6406. 6916. 8134. 8788.]