[转载] numpy.take()从数组中取指定的行或列

参考链接: Python中的numpy.take

成长需要一个过程,但是时间太漫长

  

import numpy as np

a = np.arange(12).reshape(3,4)

print(a)

print(a.take([1,2],axis = 1))#axis = 1 表示按照列来取

print(a.take([1],1))

print(a.take([1,2],axis = 0))#axis = 0 表示按照行来取

输出:

[[ 0  1  2  3]

 [ 4  5  6  7]

 [ 8  9 10 11]]

[[ 1  2]

 [ 5  6]

 [ 9 10]]

[[1]

 [5]

 [9]]

[[ 4  5  6  7]

 [ 8  9 10 11]]

Process finished with exit code 0

 参考地址: 

numpy中的ndarray方法和属性 - Q_Quan - 博客园  https://www.cnblogs.com/qquan/articles/4917434.html

猜你喜欢

转载自blog.csdn.net/u013946150/article/details/113078292
今日推荐