[問題] numpy dimension

作者: Rasin (雷森)   2021-11-30 12:47:31
In [1]: import numpy as np
In [2]: A = np.array([[1,2,3],[1,2,3]]);
In [3]: B1 = np.array([3,2,1]);
In [4]: B2 = np.array([[3,2,1]]);
In [5]: A*B1
Out[5]:
array([[3,4,3],[3,4,3]])
In [6]: A*B2
Out[6]:
array([[3,4,3],[3,4,3]])#←why 2d?
'''
A*B1 = [[1,2,3],[1,2,3]]*[3,2,1]
= [[1,2,3]*[3,2,1],[1,2,3]*[3,2,1]]
= [[3,4,3],[3,4,3]]
A*B2 = [[1,2,3],[1,2,3]]*[[3,2,1]]
= [ [1,2,3]*[[3,2,1]],[1,2,3]*[[3,2,1]] ]
= [ [[1,2,3]*[3,2,1]],[[1,2,3]*[3,2,1]] ]
= [ [[3,4,3]],[[3,4,3]] ]←why 3d?
'''
作者: lycantrope (阿寬)   2021-11-30 17:00:00
numpy broadcasting

Links booklink

Contact Us: admin [ a t ] ucptt.com