本文首发在我的个人博客:https://jlice.top/p/7dvvq/。欢迎大家前去参观,么么哒~
术语
axis
对于二维数组,垂直为轴0,水平为轴1。许多操作可以沿着一个轴进行。
>>> x = np.arange(12).reshape(3,4)
>>> x
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
>>> x.sum(axis=0)
array([12, 15, 18, 21])
>>> x.sum(axis=1)
array([ 6, 22, 38])
broadcast
Numpy可以对形状不匹配的数组执行操作
>>> np.array([2,3]