记录点滴

Home Archives About
2018-03-16
python

python sum the columns in 2D list

Python 二维数组按列求和

1.不使用 numpy

col_totals = [ sum(x) for x in zip(*my_list) ]

[stackoverflow] How do I sum the columns in 2D list?

2.使用 numpy

1
2
3
4
5
import numpy as np
a = [1, 2, 3]
b = np.array(a)
c = np.ndarray.tolist(b)

numpy数组与python的list类型的互换

1
2
3
4
5
6
>>> x = np.array([[1, 1], [2, 2]])
>>> x
array([[1, 1],
[2, 2]])
>>> x.sum(axis=0)
array([3, 3])

对Numpy数组按axis运算的理解

Share
  • 2d-array
  • python
Newer
mysql where yesterday by curdate()
Older
python argparse nargs

分类

  • bigflow
  • cpp
  • django
  • git
  • json
  • leetcode
  • linux
  • mongodb
  • mysql
  • note
  • opencv
  • python
  • redis

标签

  • 2d-array
  • bigflow
  • binary tree
  • hadoop
  • lambda
  • leetcode
  • python
  • python3

标签云

2d-array bigflow binary tree hadoop lambda leetcode python python3

归档

  • 一月 2020
  • 十二月 2018
  • 十一月 2018
  • 十月 2018
  • 九月 2018
  • 八月 2018
  • 三月 2018
  • 二月 2018
  • 一月 2018
  • 十一月 2017
  • 十月 2017
  • 九月 2017
  • 四月 2017
  • 二月 2017
  • 十一月 2012
  • 十月 2012

最新文章

  • Python requests 超时 异常捕捉
  • mysql distinct count group by
  • (no title)
  • Subarray Sum Equals K
  • Path Sum III
© 2020 Krevy Li
Powered by Hexo
Home Archives About