天天看点

numpy.sum()坐标轴问题

这里来记录一下​

​numpy.sum()​

​​函数参数​

​axis​

​​的问题。

代码如下:

import numpy as np

array = np.array([[1, 1, 1, 1],
                  [2, 2, 2, 2]])

sum_x = np.sum(array, axis=0)
sum_y = np.sum(array, axis=1)
print("The value of sum_x is: ")
print(sum_x)
print("The value of sum_y is: ")
print(sum_y)

"""
The value of sum_x is: 
[3 3 3 3]
The value of sum_y is: 
[4 8]
"""