从 sum 求和谈 axis=1 or 0
二维数组
axis=0
:表示从上往下
axis=1
:表示从左往右
temp = np.array([[1, 2], [3, 4]])
print("原矩阵数组:\n",temp)
axis0 = temp.sum(0) #从上到下求和
axis1 = temp.sum(1) #从左往右求和
print("axis0(从上到下求和):", axis0)
print("axis0(从左往右求和):", axis1)
三维数组
temp = np.array([[[1, 2],[3, 4]], [[5, 6], [7, 8]]])
print("原矩阵数组:\n",temp)
axis0 = temp.sum(0) #沿着通道层数方向求和
axis1 = temp.sum(1) #从上到下求和
axis2 = temp.sum(2) #从左往右求和
print("axis0:\n", axis0)
print("axis1:\n", axis1)
print("axis2:\n", axis2)
从 sum 求和谈 axis=1 or 0的更多相关文章
- 1.求整数最大的连续0的个数 BinaryGap Find longest sequence of zeros in binary representation of an integer.
求整数最大的连续0的个数 A binary gap within a positive integer N is any maximal sequence of consecutive zeros t ...
- [LeetCode] Binary Tree Maximum Path Sum 求二叉树的最大路径和
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. ...
- [LeetCode] 124. Binary Tree Maximum Path Sum 求二叉树的最大路径和
Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any ...
- 数位DP 求K进制下0~N的每个数每位上出现的数的总和
好久没写博客了,因为感觉时间比较紧,另一方面没有心思,做的题目比较浅也是另一方面. 热身赛第二场被血虐了好不好,于是决定看看数位DP吧. 进入正题: 如题是一道经(简)典(单)的数位dp. 第一步,对 ...
- HDU1003 Max Sum(求最大字段和)
事实上这连续发表的三篇是一模一样的思路,我就厚颜无耻的再发一篇吧! 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 -------------- ...
- HDU 1003 Max Sum 求区间最大值 (尺取法)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- [Leetcode] Binary tree maximum path sum求二叉树最大路径和
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. ...
- SGU 231 Prime Sum 求<=n内有多少对素数(a,b)使得a+b也为素数 规律题
题目链接:contest=0&problem=231">点击打开链接 题意: 求<=n内有多少对素数(a,b)使得a+b也为素数 思路: 我们发现全部素数间隔都是> ...
- 创建sum求多元素的和
a = [1, 2, 3] b = [4, 5, 6] def sum_super(* args): s = 0 for i in args: s += sum(i) return s # print ...
随机推荐
- [LC1302] 层数最深叶子节点的和
题目概述 给你一棵二叉树的根节点 root ,请你返回 层数最深的叶子节点的和 . 基本思路 这是一个简单的树的遍历的问题,可以用bfs或者dfs来解题.这里采用dfs来解,在遍历的过程中,只需要用全 ...
- Linux 终端
在 Linux 系统中,终端设备通常分为主设备和从设备.这是一种特殊的设备对的概念,其中: 主设备: 主设备也称为 "master device". 它是终端设备的控制端,用于与用 ...
- 前端学习openLayers配合vue3(加载矢量图标)
今天我们来进行矢量图标的加载 关键代码 有一个比较注意的点就是,图片路径必须引入不能直接写路径,我找半天也没发现问题所在 let anchorLayer=new VectorLayer({ sourc ...
- Solution -「AGC 039F」Min Product Sum
\(\mathscr{Description}\) Link. 对于所有 \(n\times m\) 的矩阵 \(A\), \(a_{ij}\in[1,k]\cap\mathbb N\), 求 ...
- Hadoop 概述(二)
shell定时上传linux日志信息到hdfs 从标题可以分析出来,我们要使用到shell,还要推送日志信息到hdfs上. 定义出上传的路径和临时路径,并配置好上传的log日志信息.这里我使用了上一节 ...
- C 2017笔试题
1.下面程序的输出结果是 int x=3; do { printf("%d\n",x-=2); }while(!(--x)); 输出:1 -2 解析:x初始值为3,第一次循环中运行 ...
- 060_面向过程和面向对象区别 061_对象是什么_对象和数据管理 062_对象和类的关系_属性_成员变量_方法 063_一个典型类的写法和调用_类的UML图入门 064_内存分析详解_栈_堆_方法区_栈帧_程序执行的内存变化过程
060_面向过程和面向对象区别 061_对象是什么_对象和数据管理 062_对象和类的关系_属性_成员变量_方法 public class SxtStu {//定义了一个类,包含的成员变量,属性,方法 ...
- hibernate的锁机制
概述 hibernate 可以通过加锁解决并发问题. hibernate 的锁分为两种:乐观锁和悲观锁. 乐观锁(Optimistic lock):每次访问数据时,都会乐观的认为其它事务此时肯定不会同 ...
- Java中int、Integer、long、Long、double、Double和BigInteger的关系
Java中int.Integer.long.Long.double.Double和BigInteger的关系 在Java中,int.Integer.long.Long.double.Double和Bi ...
- [国家集训队] Tree2 题解
加边删边 \(LCT\),标记下放同 \(luogu\) 线段树 \(2\) 一题. 时间复杂度 \(O(n\log n)\),第一次交的时候我维护 \(sum\) 不维护 \(sz\ WA\) 完了 ...