网络编程
位置:首页>> 网络编程>> Python编程>> numpy.sum()坐标轴问题的解决

numpy.sum()坐标轴问题的解决

作者:勤奋的大熊猫  发布时间:2023-08-23 15:05:53 

标签: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)
sum_z = 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)
print("The value of sum_z is: ")
print(sum_z)
"""
The value of sum_x is: 
[3 3 3 3]
The value of sum_y is: 
[4 8]
The value of sum_z is: 
[4 8]
"""

来源:https://blog.csdn.net/u011699626/article/details/120952744

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com